/* * 122. Best Time to Buy and Sell Stock II * 第二题,可以进行无限次,所以只要大于0的都加上 */ public int maxProfit2(int[] prices) { if (prices == null || prices.length == 0 || prices.length == 1) return 0; int res = 0; int low = prices[0]; for (int i = 1; i < prices.length; i++) { if (prices[i] > low) { res = res + prices[i] - low; } low = prices[i]; } return res; }