121. 买卖股票的最佳时机 class Solution:def maxProfit(self, prices: List[int]) -> int:cost, profit = float('+inf'), 0for price in prices:cost = min(cost, price)profit = max(profit, price - cost)return profit 122.买卖股票的最佳时机II class Solution:def maxProfit(self, prices: List[int]) -> int:profit = 0for i in range(1, len(prices)):tmp = prices[i] - prices[i - 1]if tmp > 0: profit += tmpreturn profit 123.买卖股票的最佳时机III class Solution:def maxProfit(self, prices: List[int]) -> int:k = 2f = [[-inf] * 2 for _ in range(k + 2)]for j in range(1, k + 2):f[j][0] = 0for p in prices:for j in range(k + 1, 0, -1):f[j][0] = max(f[j][0], f[j][1] + p)f[j][1] = max(f[j][1], f[j - 1][0] - p)return f[-1][0]