122. Best Time to Buy and Sell S
2017-11-24 本文已影响0人
larrymusk
这题可以不限次数交易,因此前后比较只要>0就累加入总收入里面
int maxProfit(int* prices, int pricesSize) {
int sum = 0;
int i = 0;
for(i = 1; i < pricesSize; i++){
if(prices[i]-prices[i-1] > 0)
sum += prices[i]-prices[i-1];
}
return sum;
}