easy 原题链接:https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii
最后更新于4年前
这有帮助吗?
class Solution { public: int maxProfit(vector<int>& prices) { int maxprofit=0,hold=-prices[0]; for(int i=1; i<prices.size(); i++){ hold=max(hold, maxprofit-prices[i]); maxprofit=max(maxprofit, hold+prices[i]); } return maxprofit; } };