309. 最佳买卖股票时机含冷冻期 class Solution { public: int maxProfit(vector<int>& prices) { int buy=-prices[0]; int sell=0; int cold=0; for(int i=1;i<prices.size();i++) { buy=max(buy,cold-prices[i]); cold=max(cold,sell); sell=max(sell,buy+prices[i]); } return sell; } }; 714. 买卖股票的最佳时机含手续费 class Solution { public: int maxProfit(vector<int>& prices, int fee) { int n=prices.size(); vector<int> buy(n,0); vector<int> sell(n,0); buy[0]=-prices[0]; for(int i=1;i<n;i++) { buy[i]=max(buy[i-1],sell[i-1]-prices[i]); sell[i]=max(sell[i-1],buy[i-1]+prices[i]-fee); } return sell[n-1]; } };