### Question:
MaxProfit { public int maxProfit(int[] prices) { if (prices.length <= 1) { return 0; } int winMoney = 0; List<Integer> lowDays = new ArrayList<>(); List<Integer> highDays = new ArrayList<>(); boolean isUp; if (prices[0] > prices[1]) { highDays.add(0); isUp = false; } else { lowDays.add(0); isUp = true; } for (int i = 1; i < prices.length - 1; i++) { if (isUp) { if (prices[i + 1] < prices[i]) { highDays.add(i); isUp = false; } } else { if (prices[i + 1] > prices[i]) { lowDays.add(i); isUp = true; } } } if (prices[prices.length - 1] > prices[prices.length - 2]) { highDays.add(prices.length - 1); } else if (prices[prices.length - 1] < prices[prices.length - 2]) { lowDays.add(prices.length - 1); } else if (isUp) { highDays.add(prices.length - 1); } else { lowDays.add(prices.length - 1); } int lowIndex = 0; for (Integer highDay : highDays) { if (highDay > lowDays.get(lowIndex)) { winMoney += prices[highDay] - prices[lowDays.get(lowIndex)]; lowIndex++; } } return winMoney; }  int maxProfit(int[] prices); int maxProfit2(int[] prices);  }### Answer:
@Test void go() { MaxProfit maxProfit = new MaxProfit(); for (int i = 0; i < cases.size(); i++) { assertEquals((int) results.get(i),maxProfit.maxProfit(cases.get(i))); } }