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 edddfe9 commit 1ce733bCopy full SHA for 1ce733b
best-time-to-buy-and-sell-stock/jun0811.js
@@ -0,0 +1,11 @@
1
+var maxProfit = function (prices) {
2
+ let minPrice = prices[0];
3
+ let maxProfit = 0;
4
+
5
+ for (let i = 1; i < prices.length; i++) {
6
+ minPrice = Math.min(minPrice, prices[i]);
7
+ maxProfit = Math.max(maxProfit, prices[i] - minPrice);
8
+ }
9
10
+ return maxProfit;
11
+};
0 commit comments