C# solution beat 90%


  • 0
    L
    public class Solution {
        public int MaxProfit(int[] prices) {
            var result = 0;
                if (prices != null && prices.Length > 1)
                {
                    var min = prices[0];
                    for (int i = 1; i < prices.Length; i++)
                    {
                        if (prices[i] > min)
                            result = Math.Max(result, prices[i] - min);
                        else
                            min = prices[i];
                    }
                }
                return result;
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.