Medium, 用时10分钟
- 一切从简原则, pin-point在需要关注的点
- Accumulation累加
- Greedy
public class Solution {
public int maxProfit(int[] prices) {
//8:58
if(prices.length == 1) return 0;
int length = prices.length;
int profit = 0;
for (int i = 0; i < length - 1; i++){
if(prices[i] < prices[i+1]) {
profit = profit + prices[i+1] - prices[i];
}
}
return profit;
}
}