easy to understand python solution

  • 0
    class Solution(object):
        def maxProfit(self, prices):
            :type prices: List[int]
            :rtype: int
            if not prices: return 0
            buy = sell = prices[0]
            res = 0
            for i in range(1,len(prices)):
                if prices[i] < buy:
                    buy = prices[i]
                    sell = prices[i]
                    sell = max(sell, prices[i])
                res = max(res,sell-buy)
            return res

Log in to reply

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