Python easy to understand and not slow

  • 1
    class Solution(object):
        def maxProfit(self, prices):
            :type prices: List[int]
            :rtype: int
            minp = float('inf')
            prof = 0
            for i in prices:
                if i <= minp:
                    minp = i
                if i > minp:
                    prof = max( prof, i - minp )
            return prof

Log in to reply

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