My Python Solution with DP

  • 0

    Simple Dynamic Programming Solution.

    if len(prices) <= 1:
            return 0
        MIN, res = min(prices[0], prices[1]), max(0, prices[1] - prices[0])
        for i in range(2, len(prices)):
            res = max(res, prices[i] - MIN)
            MIN = min(MIN, prices[i])
        return res

Log in to reply

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