Skip to content

Commit 8917da0

Browse files
committed
best-time-to-buy-and-sell-stock solution
1 parent 0383dda commit 8917da0

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution:
2+
def maxProfit(self, prices: List[int]) -> int:
3+
"""
4+
์ง€๊ธˆ๊นŒ์ง€ ๋ณธ ๊ฐ€๊ฒฉ ์ค‘ ๊ฐ€์žฅ ์ž‘์€ ๊ฐ’์„ ๊ณ„์† ์ €์žฅํ•˜๊ณ 
5+
ํ˜„์žฌ ๊ฐ€๊ฒฉ์—์„œ ๊ทธ ์ตœ์†Œ๊ฐ’์„ ๋บ€ ๊ฐ’์œผ๋กœ ์ตœ๋Œ€ ์ด์ต์„ ๊ฐฑ์‹ ํ•ฉ๋‹ˆ๋‹ค.
6+
ํ•œ ๋ฒˆ ์ˆœํšŒํ•˜๋ฉด์„œ ์ตœ๋Œ€ profit์„ ์ฐพ๋Š” ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค
7+
"""
8+
min_price = float('inf')
9+
max_profit = 0
10+
11+
for price in prices:
12+
min_price = min(min_price, price)
13+
max_profit = max(max_profit, price - min_price)
14+
15+
return max_profit
16+

0 commit comments

Comments
ย (0)