Python 6 lines


  • 1
    Y
    class Solution(object):
        def maxProfit(self, prices):
            """
            :type prices: List[int]
            :rtype: int
            """
            profitMax = 0
            
            minPrice = float("Inf")
            for price in prices:
                profitMax = max(profitMax, price - minPrice)
                minPrice = min(minPrice, price)
            return profitMax
    

Log in to reply
 

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