LC122 Best Time to Buy and Sell
2020-08-27 本文已影响0人
Rookie118
本题链接:Best Time to Buy and Sell Stock II
本题难度:


方案1:
class Solution {
public:
int maxProfit(vector<int>& prices) {
if(prices.size() < 2)
return 0;
int res = 0;
for(int i = 1; i < prices.size(); ++i)
res += max(prices[i] - prices[i-1], 0);
return res;
}
};
时间复杂度:
空间复杂度: