public static int maxProfit2(int[] prices) {
if (prices == null || prices.length == 0 || prices.length == 1) {
return 0;
}
int gap = 0;
int profit = 0;
for (int i = 0; i < prices.length; i++) {
if (i + 1 >= prices.length) {
continue;
}
gap = prices[i + 1] - prices[i]; //相邻两天的收益
if (gap > 0) { //如果大于0
profit += gap; //加到总收益中
}
}
return profit;
}