Best Time to Buy and Sell Stock II LeetCode solution in Java

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

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0