Simple Python code


  • 5
    W
    class Solution(object):
        def maxProfit(self, prices):
            """
            :type prices: List[int]
            :rtype: int
            """
            n=len(prices)
            if n<=1:
                return 0
            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

  • 0
    L
    This post is deleted!

  • 0
    M

    And this is kadane algorithm correct?


Log in to reply
 

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