题目描述:
方法一:
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