Skip to content
This repository was archived by the owner on Apr 20, 2024. It is now read-only.

Commit e35c630

Browse files
committed
created another solution for problem65
1 parent a55944b commit e35c630

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

problem65/Solution2.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
def maxProfit(self, prices: List[int], fee: int) -> int:
3+
min_price = prices[0] + fee
4+
max_profit = 0
5+
6+
for price in prices:
7+
if min_price < price:
8+
# Sell stock at this price
9+
max_profit += price - min_price
10+
11+
min_price = price
12+
13+
elif price + fee < min_price:
14+
# Buy stock at this price
15+
min_price = price+fee
16+
17+
return max_profit

0 commit comments

Comments
 (0)