要求:做波段
思路:后大于前的都加上,也太简单了
class Solution {
public:
int maxProfit(vector<int>& prices) {
int n=prices.size();
int maxprofit=0;
for(int i=0;i+1<n;++i)
if(prices[i]<prices[i+1])
maxprofit+=prices[i+1]-prices[i];
return maxprofit;
}
};