LeetCode 309. Best Time to Buy and Sell Stock with Cooldown
程序员文章站
2022-06-17 18:25:33
...
Poblem
Notes
此题解法完全参考他人博客。
发这篇博文作为自己的一个做题记录。
Codes
class Solution {
public:
int maxProfit(vector<int>& prices) {
int n=prices.size();
if(n<=1) return 0;
int pre0=0,pre1=0,pre2=0;
int s0=0,s1=-prices[0],s2=INT_MIN;
for(int i=1;i<n;++i)
{
pre0=s0;
pre1=s1;
pre2=s2;
s0=max(pre0,pre2);
s1=max(pre1,pre0-prices[i]);
s2=pre1+prices[i];
}
return max(s0,s2);
}
};
Results
推荐阅读
-
LeetCode_Array_123. Best Time to Buy and Sell Stock III买卖股票的最佳时机III(C++)
-
Leetcode No.121 Best Time to Buy and Sell Stock(c++实现)
-
309. Best Time to Buy and Sell Stock with Cooldown
-
Leetcode 309. Best Time to Buy and Sell Stock with Cooldown
-
[LeetCode] 309. Best Time to Buy and Sell Stock with Cooldown
-
【DP + 卖股票】LeetCode 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
-
(M)Dynamic Programming:309. Best Time to Buy and Sell Stock with Cooldown
-
309. Best Time to Buy and Sell Stock with Cooldown