71. House Robber

Houses on a street hold nums[i] money. You cannot rob two adjacent houses. Return the maximum amount you can rob.

Example 1

Input: nums = [2,7,9,3,1]
Output: 12
Explanation: Rob houses with 2, 9 and 1.

Example 2

Input: nums = [6,7,1,30,8,2,4]
Output: 41
Explanation: Rob 7, 30 and 4.
Hint 1

dp[i] = max(dp[i−1], dp[i−2] + nums[i]): either skip house i or rob it.

Dynamic Programming