Simpe Python Code (Runtime - 48ms)


  • 0
    M
    class Solution(object):
        def maxProfit(self, prices):
            """
            :type prices: List[int]
            :rtype: int
            """
            profit = 0
            index = 0
            for i in range(1,len(prices)):
                if prices[index] < prices[i]:
                    temp = prices[i] - prices[index] 
                    if temp  > profit:
                        profit = temp
                else:
                    index = i
            return profit

Log in to reply
 

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