House Robber

LeetCode

LeetCode: https://leetcode.com/problems/house-robber/

You are given an integer array nums representing the amount of money of each house. You cannot rob adjacent houses. Return the maximum amount you can rob.

1def rob(nums: List[int]) -> int:
2 rob1, rob2 = 0, 0
3 for x in nums:
4 newRob = max(rob1 + x, rob2)
5 rob1 = rob2
6 rob2 = newRob
7 return rob2
i
2
0
7
1
9
2
3
3
1
4
rob1=0
rob2=0
Step 1 / 7
Step 1:
Track rob1=best up to i-2 and rob2=best up to i-1. Start at 0.
Pointers: i=0
Focus: select @ [0]
rob1=0rob2=0