class Solution {
public:
int maxProfit(vector<int>& prices) {
int sum = 0;
for(int i=1; i<prices.size(); i++){
if(prices[i] > prices[i-1]){
sum += prices[i] - prices[i-1];
}
}
return sum;
}
};
leetcode122+Best Time to Buy and Sell Stock II
最新推荐文章于 2024-11-01 15:19:21 发布