Skip to content

Commit 7f6ea6f

Browse files
committed
198
1 parent a302fff commit 7f6ea6f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

house-robber/jeldo.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution:
2+
# O(n)
3+
def rob(self, nums: list[int]) -> int:
4+
if len(nums) <= 2:
5+
return max(nums)
6+
nums[2] += nums[0]
7+
for i in range(3, len(nums)):
8+
nums[i] += max(nums[i-3], nums[i-2])
9+
return max(nums[-1], nums[-2])

0 commit comments

Comments
 (0)