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 cf65e7b commit 9c736adCopy full SHA for 9c736ad
best-time-to-buy-and-sell-stock/lhc0506.js
@@ -0,0 +1,15 @@
1
+/**
2
+ * @param {number[]} prices
3
+ * @return {number}
4
+ */
5
+var maxProfit = function(prices) {
6
+ let minPrice = Number.MAX_SAFE_INTEGER;
7
+ let maxProfit = 0;
8
+
9
+ for (let i = 0; i < prices.length; i++) {
10
+ minPrice = Math.min(minPrice, prices[i]);
11
+ maxProfit = Math.max(maxProfit, prices[i] - minPrice);
12
+ }
13
14
+ return maxProfit;
15
+};
0 commit comments