Skip to content

Commit cdb6714

Browse files
author
jinbeom
committed
Best Time to Buy and Sell Stock Solution
1 parent 570eaeb commit cdb6714

File tree

1 file changed

+15
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)