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 edddfe9 commit 9100c95Copy full SHA for 9100c95
best-time-to-buy-and-sell-stock/hyunjung-choi.kt
@@ -0,0 +1,18 @@
1
+/**
2
+ * 시간 복잡도: O(n)
3
+ * 공간 복잡도: O(1)
4
+ */
5
+
6
+class Solution {
7
+ fun maxProfit(prices: IntArray): Int {
8
+ var minPrice = Int.MAX_VALUE
9
+ var maxProfit = 0
10
11
+ prices.forEach { price ->
12
+ minPrice = minOf(minPrice, price)
13
+ maxProfit = maxOf(maxProfit, price - minPrice)
14
+ }
15
16
+ return maxProfit
17
18
+}
0 commit comments