买卖股票的最佳时机 II
public int maxProfit(int[] prices) {
int bef = 0;
// 贪心解法,遍历数组,发现后面的价格大于当前的价格,就计算利润
for (int i = 1; i < prices.length; i ++) {
if (prices[i] > prices[i - 1]) {
bef += prices[i] - prices[i - 1];
}
}
return bef;
}