simple python solution


  • 2
    X
    class Solution(object):
        def maxProfit(self, prices):
            """
            :type prices: List[int]
            :rtype: int
            """
            n = len(prices)
            if n>1:
                max_profit = 0
                low_price = prices[0]
                for i in range(1,n):
                    low_price=min(low_price,prices[i])
                    max_profit=max(max_profit, prices[i]-low_price)
                return max_profit
            else:
                return 0
    

Log in to reply
 

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