目录
目录
学习目标
学习内容
309.最佳买卖股票时机含冷冻期
714.买卖股票的最佳时机含手续费
学习目标
- 309.最佳买卖股票时机含冷冻期
- 714.买卖股票的最佳时机含手续费
- 总结
学习内容
309.最佳买卖股票时机含冷冻期
309. 最佳买卖股票时机含冷冻期 - 力扣(LeetCode)https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-with-cooldown/
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.买卖股票的最佳时机含手续费
714. 买卖股票的最佳时机含手续费 - 力扣(LeetCode)https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-with-transaction-fee/
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
problems/动态规划-股票问题总结篇.md · programmercarl/leetcode-master(代码随想录出品) - Gitee.comhttps://gitee.com/programmercarl/leetcode-master/blob/master/problems/%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92-%E8%82%A1%E7%A5%A8%E9%97%AE%E9%A2%98%E6%80%BB%E7%BB%93%E7%AF%87.md