Skip to content

Commit 802470e

Browse files
committed
feat : best-time-to-buy-and-sell-stock
1 parent ceb26c5 commit 802470e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
public int maxProfit(int[] prices) {
3+
int minPrice = Integer.MAX_VALUE;
4+
int maxProfit = 0;
5+
for(int i = 0; i < prices.length; i++) {
6+
minPrice = Math.min(minPrice, prices[i]);
7+
maxProfit = Math.max(maxProfit, prices[i] - minPrice);
8+
}
9+
return maxProfit;
10+
}
11+
}

0 commit comments

Comments
 (0)