贪心。
class Solution { public: int maxProfit(vector<int>& prices) { int now=prices.front(); //现在手中买入价 int profit=0; prices.push_back(prices.back()); for (int i=0;i<prices.size()-1;i++) if (prices[i+1]<prices[i]) //明天将跌 profit+=(prices[i]-now),now=prices[i+1]; return profit+prices.back()-now; } };