We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 9db6629 commit 53d6decCopy full SHA for 53d6dec
1 file changed
Dynamic Programming/2D/Stocks/BuySell1Greedy.java
@@ -0,0 +1,13 @@
1
+class BuySell1Greedy {
2
+ public int maxProfit(int[] prices) {
3
+ int minValue = Integer.MAX_VALUE;
4
+ int maxProfit = Integer.MIN_VALUE;
5
+
6
+ for(int i = 0; i<prices.length; i++){
7
+ minValue = Math.min(prices[i], minValue);
8
+ maxProfit = Math.max(maxProfit, prices[i]-minValue);
9
+ }
10
11
+ return maxProfit;
12
13
+}
0 commit comments