class Solution {
public:
int maxProfit(vector<int>& prices) {
if(prices.size() < 2) return 0;
int max_profit = 0;
for(int i = 1;i < prices.size(); ++i){
int tmp = prices[i] - prices[i-1];
if(tmp > 0)
max_profit += tmp;
}
return max_profit;
}
};
只要上涨就加上。