One line by Java 8 Stream


  • 0
    X
    public int maxProfit(int[] prices) {
        return IntStream.range(1, prices.length).map(i -> prices[i] > prices[i - 1] ? prices[i] - prices[i - 1] : 0).sum();
    }
    

Log in to reply
 

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