JAVA easy solution 1 ms, O(N). Comments appreciated!


  • 1
    R
    public int maxProfit(int[] prices) {
        int len=prices.length;
        if(len==0) return 0;
        
        int min=prices[0],max=0;
        for(int i=0;i<len;i++){
            if(prices[i]<min) min=prices[i];
            prices[i]-=min;
            if(max<prices[i]) max=prices[i];
         }
         return max;
    }

  • 0
    A

    shit solution!


Log in to reply
 

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