Skip to content

Latest commit

 

History

History
18 lines (18 loc) · 356 Bytes

121.md

File metadata and controls

18 lines (18 loc) · 356 Bytes
class Solution {
    public int maxProfit(int[] prices) {
    if(prices.length==0){
        return 0;
    }
    int left = prices[0], sum = 0;
    for (int i = 1; i < prices.length; i++) {
      if (left < prices[i]) {
        sum = Math.max(sum, prices[i] - left);
      } else {
        left = prices[i];
      }
    }
    return sum;
    }
}