C#
CSHARP\npublic int MaxProfit(int[] prices)\n{\n\tif (prices.Length == 0) return 0;\n\n\tint min = int.MaxValue;\n\tint max = int.MinValue;\n\n\tfor(int i = 0; i
```CSHARP\npublic int MaxProfit(int[] prices)\n{\n\tif (prices.Length == 0) return 0;\n\n\tint min = int.MaxValue;\n\tint max = int.MinValue;\n\n\tfor(int i = 0; i < prices.Length; i++)\n\t{\n\t\tmin = Math.Min(min, prices[i]);\n\t\tmax = Math.Max(max, prices[i] - min);\n\t}\n\n\treturn max;\n}\n```
[]