Skip to content

Commit d02e5dd

Browse files
committed
feat: Best Time to Buy and Sell Stock
1 parent 845cdbd commit d02e5dd

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# 시간 복잡도 : O(n)
2+
# 공간 복잡도 : O(1)
3+
class Solution:
4+
def maxProfit(self, prices: List[int]) -> int:
5+
min_price = float('inf')
6+
max_profit = 0
7+
8+
for price in prices:
9+
min_price = min(min_price, price)
10+
max_profit = max(max_profit, price - min_price)
11+
12+
return max_profit
13+

0 commit comments

Comments
 (0)