Skip to content

Commit 5ac7e7d

Browse files
week 5: Best Time to Buy and Sell Stock
1 parent d745086 commit 5ac7e7d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
def maxProfit(self, prices: List[int]) -> int:
3+
max_profit = 0
4+
buy_price = float('inf')
5+
6+
for price in prices:
7+
buy_price = min(buy_price, price)
8+
current_profit = price - buy_price
9+
max_profit = max(max_profit, current_profit)
10+
11+
return max_profit

0 commit comments

Comments
 (0)