Skip to content

Commit 7f1d352

Browse files
authored
Merge pull request neetcode-gh#310 from SharmaTushar1/patch-7
Create 121-Best-Time-to-Buy-and-Sell-Stock.java
2 parents 730a68b + b892ed6 commit 7f1d352

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 min = Integer.MAX_VALUE;
4+
int ans = Integer.MIN_VALUE;
5+
for (int val: prices) {
6+
min = Math.min(min, val);
7+
ans = Math.max(ans, val - min);
8+
}
9+
return ans;
10+
}
11+
}

0 commit comments

Comments
 (0)