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.
1 parent ceb26c5 commit 802470eCopy full SHA for 802470e
best-time-to-buy-and-sell-stock/ekgns33.java
@@ -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