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 80d8f88 commit 4a5bc50Copy full SHA for 4a5bc50
best-time-to-buy-and-sell-stock/RiaOh.js
@@ -0,0 +1,15 @@
1
+/**
2
+ * @param {number[]} prices
3
+ * @return {number}
4
+ */
5
+var maxProfit = function (prices) {
6
+ // 가장 작은 수
7
+ let minNum = prices[0];
8
+ // 차이 값
9
+ let maxProfit = 0;
10
+ for (let i = 1; i < prices.length; i++) {
11
+ minNum = Math.min(minNum, prices[i - 1]); // 이전꺼 중 가장 작은 수
12
+ maxProfit = Math.max(maxProfit, prices[i] - minNum);
13
+ }
14
+ return maxProfit;
15
+};
0 commit comments