最后更新于4年前
这有帮助吗?
medium
解法:
class Solution { public: int maxProfit(vector<int>& prices, int fee) { int maxprofit=0, hold=-prices[0]; for(int i=1; i<prices.size(); i++){ maxprofit=max(maxprofit,hold+prices[i]-fee); hold=max(hold,maxprofit-prices[i]); } return maxprofit; } };
解法