leetcode-123-买卖股票的最佳时机③

 

 题目描述:

leetcode-123-买卖股票的最佳时机③

leetcode-123-买卖股票的最佳时机③

 

 方法一:

class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        dp_i1_0 = 0
        dp_i1_1 = float('-inf')
        dp_i2_0 = 0
        dp_i2_1 = float('-inf')
        for price in prices:
            dp_i2_0 = max(dp_i2_0,dp_i2_1 + price)
            dp_i2_1 = max(dp_i2_1,dp_i1_0 - price)
            dp_i1_0 = max(dp_i1_0,dp_i1_1 + price)
            dp_i1_1 = max(dp_i1_1, - price)
        return dp_i2_0

 

上一篇:父类指针强转为子类指针的问题


下一篇:opencv Mat