Skip to content

Commit 24df097

Browse files
iamAntimPalAntim-IWPIamShiwangi
committed
Update 198. House Robber.py
Co-Authored-By: Antim-IWP <203163676+Antim-IWP@users.noreply.github.com> Co-Authored-By: Shiwangi Srivastava <174641070+IamShiwangi@users.noreply.github.com>
1 parent 0285c47 commit 24df097

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution:
2+
def rob(self, nums: List[int]) -> int:
3+
@cache
4+
def dfs(i: int) -> int:
5+
if i >= len(nums):
6+
return 0
7+
return max(nums[i] + dfs(i + 2), dfs(i + 1))
8+
9+
return dfs(0)

0 commit comments

Comments
 (0)