leetcode-买卖股票最佳时机含冷冻期

题目描述:

方法一:

class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        n = len(prices)
        dp_i_0 = 0
        dp_i_1 = float('-inf')
        dp_pre_0 = 0
        for i in range(0,n):
            temp = dp_i_0
            dp_i_0 = max(dp_i_0,dp_i_1 + prices[i])
            dp_i_1 = max(dp_i_1,dp_pre_0 - prices[i])
            dp_pre_0 = temp
        return dp_i_0

 

posted @ 2019-07-15 18:54  oldby  阅读(210)  评论(0编辑  收藏  举报