构造
贪心+栈
贪心+队列
局部最优增加进一步优化的可能
-
买卖股票
- buy 的值为prices[0] 加上手续费fee
- 如果当前价格prices[i] + fee < buy,说明此时价格更低,更新buy = prices[i] + fee
- 如果当前价格prices[i] > buy,此时可以卖出,盈余prices[i] - buy;此时未必是最优解;增加反悔策略;a:更新buy = prices[i],如果第二天上涨,此时直接更新,prices[i + 1] - prices[i],相当于prices[i + 1] - buy;