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 d89fefb commit 13b9ddbCopy full SHA for 13b9ddb
best-time-to-buy-and-sell-stock/s0ooo0k.java
@@ -0,0 +1,14 @@
1
+class Solution {
2
+ public int maxProfit(int[] prices) {
3
+ int price = prices[0];
4
+ int maxProfit = 0;
5
+
6
+ for(int i=1; i<prices.length; i++){
7
+ int profit = prices[i]-price;
8
+ maxProfit = Math.max(maxProfit, profit);
9
+ price = Math.min(price, prices[i]);
10
+ }
11
+ return maxProfit;
12
13
+}
14
0 commit comments