309. Best Time to Buy and Sell Stock with Cooldown
程序员文章站
2022-06-17 18:25:39
...
class Solution {
public:
int maxProfit(vector<int>& prices) {
int buy = INT_MIN;
int pre_buy;
int sell = 0;
int pre_sell = 0;
for (int i = 0; i < prices.size(); i++) {
pre_buy = buy;
buy = max(pre_sell - prices[i], buy);
pre_sell = sell;
sell = max(pre_buy + prices[i], sell);
}
return sell;
}
};
上一篇: (M)Dynamic Programming:309. Best Time to Buy and Sell Stock with Cooldown
下一篇: LeetCode 309. Best Time to Buy and Sell Stock with Cooldown
推荐阅读
-
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