Skip to content

Commit e9f8a75

Browse files
author
sejineer
committed
best-time-to-buy-and-sell-stock solution
1 parent 0b89fcc commit e9f8a75

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
시간 복잡도: O(N)
3+
공간 복잡도: O(1)
4+
"""
5+
class Solution:
6+
def maxProfit(self, prices: List[int]) -> int:
7+
buy = prices[0]
8+
result = 0
9+
10+
for price in prices:
11+
profit = price - buy
12+
buy = min(buy, price)
13+
result = max(profit, result)
14+
15+
return result

0 commit comments

Comments
 (0)