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 479a691 commit 2b976cdCopy full SHA for 2b976cd
best-time-to-buy-and-sell-stock/yihyun-kim1.js
@@ -0,0 +1,15 @@
1
+/**
2
+ * @param {number[]} prices
3
+ * @return {number}
4
+ */
5
+const maxProfit = (prices) => {
6
+ let minPrice = prices[0];
7
+ let maxProfit = 0;
8
+
9
+ for (let i = 1; 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