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 abcb7d3 commit dedc040Copy full SHA for dedc040
best-time-to-buy-and-sell-stock/krokerdile.js
@@ -0,0 +1,14 @@
1
+var maxProfit = function(prices) {
2
+ let minPrice = Infinity;
3
+ let maxProfit = 0;
4
+
5
+ for (let price of prices) {
6
+ if (price < minPrice) {
7
+ minPrice = price; // 더 싼 가격이 나타나면 갱신
8
+ } else {
9
+ maxProfit = Math.max(maxProfit, price - minPrice); // 이익 갱신
10
+ }
11
12
13
+ return maxProfit;
14
+};
0 commit comments