Skip to content

Commit

Permalink
[LC-0122] Best Time to Buy and Sell Stock II
Browse files Browse the repository at this point in the history
Add java solution for leetcode problem 122 - Best Time to Buy and Sell Stock II
  • Loading branch information
galaumang committed May 9, 2023
1 parent 41677f3 commit 3f886a5
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions solutions-java/src/main/java/dsalgo/leetcode/BuySellStock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package dsalgo.leetcode;

public class BuySellStock {
public int maxProfit(int[] prices) {
int profit = 0;
for (int i = 1; i < prices.length; i++) {
if (prices[i] > prices[i-1])
profit += prices[i] - prices[i-1];
}
return profit;
}
}

0 comments on commit 3f886a5

Please sign in to comment.