目录
目录
学习目标
- 309.最佳买卖股票时机含冷冻期
- 714.买卖股票的最佳时机含手续费
- 总结
学习内容
309.最佳买卖股票时机含冷冻期
class Solution:
def maxProfit(self, prices: List[int]) -> int:
n = len(prices)
a = 0 # 无
b = 0 # 冷静期
c = -prices[0] # 有
d = 0 # 卖
for i in range(1,n):
a = max(a,b)
b = d
c = max(c,a-prices[i])
d = c+prices[i]
return max(a,b,d)
714.买卖股票的最佳时机含手续费
class Solution:
def maxProfit(self, prices: List[int], fee: int) -> int:
n = len(prices)
a = 0
b = -prices[0]-fee
for i in range(1,n):
a = max(a,b+prices[i])
b = max(b,a-prices[i]-fee)
return a