LeetCode:122 买卖股票的最佳时机 Ⅱ
class Solution { public int maxProfit(int[] prices) { int len = prices.length; int res = 0; int i = 0; while(i < len - 1){ while(i < len - 1 && prices[i] >= prices[i+1]){ i++; } int t = prices[i]; while(i < len - 1 && prices[i] <= prices[i+1]){ i++; } int x = prices[i]; res += x - t; } return res; } }