leetcode 122.买卖股票的最佳时机Ⅱ
作者:互联网
贪心。
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; } };
标签:vector,int,back,maxProfit,profit,122,最佳时机,prices,leetcode 来源: https://www.cnblogs.com/wegret/p/14872450.html