Leetcode.Best-time-to-buy-and-sell-stock

Task

public class Solution {
    public int MaxProfit(int[] prices) {
                        
        int min = 11000;        

        int profit = 0;
        int maxProfit = 0;            

        for (int i = 0; i < prices.Length; i++) {
          
        if (prices[i] < min) {
            min = prices[i];            
          }          

          profit = prices[i] - min; 
          if (profit > maxProfit)
            maxProfit = profit;                                    
        }

        return maxProfit;
    }
}
This entry was posted in Без рубрики. Bookmark the permalink.