1public int maxProfit(int[] prices) {
2 int maxProfit = 0;
3
4 for (int i = 1; i < prices.length; i++) {
5 if (prices[i] > prices[i - 1]) {
6 maxProfit += prices[i] - prices[i - 1];
7 }
8 }
9
10 return maxProfit;
11}