class Solution {
public:
int maxProfit(vector<int>& prices) {
if(prices.empty())return 0;
int profit=0;
for(int i=1;i<prices.size();++i){
int inc=prices[i]-prices[i-1];
profit+=inc>0?inc:0;
}
return profit;
}
};
122. Best Time to Buy and Sell Stock II
最新推荐文章于 2022-11-16 09:46:40 发布