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 8a4a45d commit f1aa488Copy full SHA for f1aa488
1 file changed
best-time-to-buy-and-sell-stock/gcount85.py
@@ -0,0 +1,21 @@
1
+"""
2
+# Approach
3
+지금까지의 최저 가격을 갱신함과 동시에 최선의 이익도 업데이트합니다.
4
+
5
+# Complexity
6
+- Time complexity: O(N)
7
8
+- Space complexity: O(1)
9
10
11
12
+class Solution:
13
+ def maxProfit(self, prices: list[int]) -> int:
14
+ min_price = float("inf")
15
+ answer = 0
16
17
+ for price in prices:
18
+ min_price = min(min_price, price)
19
+ answer = max(answer, price - min_price)
20
21
+ return answer
0 commit comments