714. 买卖股票的最佳时机含手续费 题目 思路 过一遍,记录第i天是否买入和卖出的最值。 代码 class Solution { public: int maxProfit(vector<int>& prices, int fee) { int l=prices.size(); int s=0,h=-prices[0]; for(int i=1;i<l;i++) { s=max(s,h+prices[i]-fee); h=max(h,s-prices[i]); } return s; } };