Skip to content

Commit 922cbb6

Browse files
authored
Merge pull request #17 from iamAntimPal/Leetcode-75
Leetcode 75
2 parents cab42de + a236531 commit 922cbb6

File tree

2 files changed

+415
-0
lines changed

2 files changed

+415
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def maxProfit(self, prices: List[int], fee: int) -> int:
3+
@cache
4+
def dfs(i: int, j: int) -> int:
5+
if i >= len(prices):
6+
return 0
7+
ans = dfs(i + 1, j)
8+
if j:
9+
ans = max(ans, prices[i] + dfs(i + 1, 0) - fee)
10+
else:
11+
ans = max(ans, -prices[i] + dfs(i + 1, 1))
12+
return ans
13+
14+
return dfs(0, 0)

0 commit comments

Comments
 (0)