Best Time to Buy and Sell Stock II
class Solution {
public int maxProfit(int[] prices) {
if(prices == null || prices.length == 0)
return 0;
int prev = prices[0];
int sum = 0;
for(int p : prices){
if(p > prev){
sum += p - prev;
}
prev = p;
}
return sum;
}
}Last updated