One-liner pythonic solution


  • 0
    A
    def maxProfit(self, prices):
        return sum((prices[i]-prices[i-1] for i in range(1,len(prices)) if prices[i-1] < prices[i]))

Log in to reply
 

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