We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 730a68b + b892ed6 commit 7f1d352Copy full SHA for 7f1d352
java/121-Best-Time-to-Buy-and-Sell-Stock.java
@@ -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