Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 74cf0f4

Browse files
authored
Update and rename Easy/Best time to buy & sell a stock II.java to Medium/Best Time to Buy and Sell Stock II.java
1 parent 537c3fb commit 74cf0f4

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

Easy/Best time to buy & sell a stock II.java

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public int maxProfit(int[] prices) {
3+
int stockBuyPrice = Integer.MAX_VALUE;
4+
int profit = 0;
5+
for (int i = 0; i < prices.length; i++) {
6+
if (prices[i] > stockBuyPrice) {
7+
profit += prices[i] - stockBuyPrice;
8+
stockBuyPrice = prices[i];
9+
} else {
10+
stockBuyPrice = prices[i];
11+
}
12+
}
13+
return profit;
14+
}
15+
}

0 commit comments

Comments
 (0)