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.
2 parents b6b287a + 8fd950f commit de3162cCopy full SHA for de3162c
โbest-time-to-buy-and-sell-stock/yuhyeon99.jsโ
@@ -0,0 +1,19 @@
1
+/**
2
+ * @param {number[]} prices
3
+ * @return {number}
4
+ * i ๋ฒ์งธ ๋ ์ ์ฃผ์์ ๊ฐ๊ฒฉ์ prices[i]์ ๋ด๊ณ ์๋ ๋ฐฐ์ด prices๊ฐ ์ฃผ์ด์ก์ ๋,
5
+ * ์ฃผ์์ ์ด๋ค ๋ ์ ํ ๋ฒ ์ฌ๊ณ ๋์ค์ ๋ค๋ฅธ ๋ ์ ํ์์ ๋ฌ์ฑ ๊ฐ๋ฅํ ์ต๋ ์ด์ต์ ๊ตฌํ๋ผ.
6
+ *
7
+ */
8
+var maxProfit = function(prices) {
9
+ var maxProfit = 0;
10
+ var minPrice = prices[0]
11
+
12
+ for(let i = 0; i < prices.length; i ++) {
13
+ let profit = prices[i] - minPrice;
14
+ maxProfit = Math.max(profit, maxProfit);
15
+ minPrice = Math.min(prices[i], minPrice);
16
+ }
17
18
+ return maxProfit;
19
+};
0 commit comments