Skip to content

Commit 7e559b3

Browse files
authored
Create 122. Best Time to Buy and Sell Stock II.java
1 parent 9934165 commit 7e559b3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii
2+
3+
public class Solution {
4+
public int maxProfit(int[] prices) {
5+
if (prices.length <= 1) return 0;
6+
7+
int maxProfit = 0;
8+
9+
for (int i = 1; i < prices.length; i++) {
10+
maxProfit += Math.max(0, prices[i] - prices[i-1]);
11+
}
12+
13+
return maxProfit;
14+
}
15+
}

0 commit comments

Comments
 (0)