Best Time to Buy and Sell Stock with Cooldown
来源:互联网 发布:做seo需要什么技能 编辑:程序博客网 时间:2024/05/16 08:28
c++
class Solution {public: int maxProfit(vector<int>& prices) { if (prices.empty()) return 0; int pre_buy = -prices[0]; int pre_sell = INT_MIN; int pre_rest = 0; for (int i = 1; i < prices.size(); ++i) { int buy = max(pre_rest - prices[i], pre_buy); int sell = max(pre_rest, pre_buy + prices[i]); int rest = max(max(pre_rest, pre_buy), pre_sell); pre_buy = buy; pre_sell = sell; pre_rest = rest; } return max(pre_sell, pre_rest); }};
reference:
https://leetcode.com/discuss/71354/share-my-thinking-process
https://leetcode.com/discuss/72030/share-my-dp-solution-by-state-machine-thinking
0 0
- 309Best Time to Buy and Sell Stock with Cooldown
- leetcode Best Time to Buy and Sell Stock with Cooldown
- Best Time to Buy and Sell Stock with Cooldown
- Leetcode197: Best Time to Buy and Sell Stock with Cooldown
- LeetCode Best Time to Buy and Sell Stock with Cooldown
- Leetcode: Best Time to Buy and Sell Stock with Cooldown
- Best Time to Buy and Sell Stock with Cooldown
- [LeetCode]Best Time to Buy and Sell Stock with Cooldown
- Leetcode Best Time to Buy and Sell Stock with Cooldown
- leetcode - Best Time to Buy and Sell Stock with Cooldown
- Best Time to Buy and Sell Stock with Cooldown
- LeetCode:Best Time to Buy and Sell Stock with Cooldown
- 309.Best Time to Buy and Sell Stock with Cooldown
- 309. Best Time to Buy and Sell Stock with Cooldown
- 309. Best Time to Buy and Sell Stock with Cooldown
- 309. Best Time to Buy and Sell Stock with Cooldown
- leetcode_309 Best Time to Buy and Sell Stock with Cooldown
- 309. Best Time to Buy and Sell Stock with Cooldown
- 数据结构 最小堆
- ACCESS 窗体组合框查询表名
- Struts 2.3.29 Dispatcher initialization failed问题
- java invoke简单入门例子(基于JDK接口实现)
- androidstudio下NDK正确姿势
- Best Time to Buy and Sell Stock with Cooldown
- Maven利用tomcat7发布Web
- 【Get深一度】GRE和托福的区别
- hrbust 1594 Gragon Ball【模拟】
- 通过一个简单的例子,说明class文件在运行过程中,import中class怎么被加载并执行的
- C++补第一次实验
- Json数据解析和生成(C/C++, 使用CJson)
- IOS实现Voip应用后台运行需要的几个配置项
- 关于“微信订阅号/制作相册”