class Solution {
public:
int maxProfit(vector<int> &prices) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(prices.size()<=1)
return 0;
int max=0;
for(int i=1;i<prices.size();++i){
if(prices[i]>prices[i-1])
max+=(prices[i]-prices[i-1]);
}
return max;
}
};
Leetcode: Best Time to Buy and Sell Stock II
最新推荐文章于 2020-04-12 22:35:46 发布
