思路
leetcode上买卖股票系列问题:
- 121. Best Time to Buy and Sell Stock 只能买卖一次
- 122. Best Time to Buy and Sell Stock II 能买卖无数次
- 123. Best Time to Buy and Sell Stock III 至多买卖2次
- 188. Best Time to Buy and Sell Stock IV 至多买卖k次
- 309. Best Time to Buy and Sell Stock with Cooldown 能买卖无数次,但有冷静期
- 714. Best Time to Buy and Sell Stock with Transaction Fe
e 能买卖无数次,但是每次交易有手续费
大体思路都是DP,用通用解法能暴力过121、122、123,稍加修改能过309。
188用通用解法会提示runtime error,需要进行状态压缩,解法可以参考这个;
通用解法
1 | var maxProfit = function (maxTransTimes, prices) { |