Buy and sell stock:any problem in my solution


  • -1
    S
    public int maxProfit(int[] prices) {
            if (prices.length <= 1) return 0;
            int max = Integer.MIN_VALUE;
            int curr = prices[0];
            for (int i = 1; i < prices.length; i++) {
                if ((prices[i] - curr) < 0)
                    curr = prices[i];
                max = Math.max(max, prices[i] - curr);
            }
            return max;
        }

  • 0
    T

    You summited the stock transaction question under the median problem. wrong place!


Log in to reply
 

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