Python easy DP solution

  • 0
    class Solution(object):
        def maxProfit(self, prices, fee):
            :type prices: List[int]
            :type fee: int
            :rtype: int
            if not prices or len(prices)<2: return 0
            buy = -prices[0]
            sell = 0
            for i, v in enumerate(prices,1):
                buy,sell = max(buy,sell-v),max(sell,buy+v-fee)
            return sell

Log in to reply

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