Skip to content

Commit 986cf0b

Browse files
122. Best Time to Buy and Sell Stock II (java)
1 parent 5f90658 commit 986cf0b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
public int maxProfit(int[] prices) {
3+
int maxProfit = 0;
4+
for (int i = 0; i < prices.length; i++) {
5+
if (i + 1 < prices.length && prices[i + 1] - prices[i] > 0) {
6+
maxProfit += prices[i + 1] - prices[i];
7+
}
8+
}
9+
return maxProfit;
10+
}
11+
}

0 commit comments

Comments
 (0)