Skip to content

Commit

Permalink
feature: best time to buy and sell stock with transaction fee revisit
Browse files Browse the repository at this point in the history
  • Loading branch information
solairerove committed Nov 22, 2023
1 parent 096b09b commit 7a02a2b
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# O(n) time || O(1) space
def max_profit(self, prices: List[int], fee: int) -> int:
res, hold = 0, -prices[0]
for i in range(1, len(prices)):
res = max(res, hold + prices[i] - fee)
hold = max(hold, res - prices[i])
for price in prices[1:]:
res = max(res, hold + price - fee)
hold = max(hold, res - price)

return res

0 comments on commit 7a02a2b

Please sign in to comment.