![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode买卖股票
只会写臭虫
这个作者很懒,什么都没留下…
展开
-
LeetCode 121 买卖股票的最佳时机
代码:class Solution {public: int maxProfit(vector<int>& prices) { int minp=100000000; //当前最小的price int size=prices.size(); int maxp=0; //当前最大的利润 for(int ...转载 2019-06-30 15:59:44 · 206 阅读 · 0 评论 -
LeetCode122. 买卖股票的最佳时机 II
class Solution {public: int maxProfit(vector<int>& prices) { int ans=0; for(int i=1;i<prices.size();i++) if(prices[i]>prices[i-1]) ans...转载 2019-06-30 16:02:11 · 86 阅读 · 0 评论 -
LeetCode123. 买卖股票的最佳时机 III
定义dp[n][k][m],表示第n天结束后,状态为m,已经购买的股票数为k。m=1表示持有股票,m=0表示当前不持有股票。k的取值为0,1,2。写的时候迷迷糊糊的,感觉还是没有掌握精髓。。。。代码:class Solution {public: int dp[100000][3][2]; int min_int = -2000000000; //不存你在的状态设置为很小,...原创 2019-06-30 20:09:04 · 264 阅读 · 0 评论 -
LeetCode 309. 最佳买卖股票时机含冷冻期
代码中有注释,需要注意的一点是dp[10000][3]定义的是第i天结束后的状态。用0表示持有股票,1表示不持有,2表示冷冻期代码:class Solution {public: int dp[10000][3]; //dp定义了第i天结束后的状态,0代表不持有,1代表持有,2代表是冷冻期 int maxProfit(vector<int>& price...原创 2019-06-30 20:12:03 · 108 阅读 · 0 评论