House Robber

Medium

nums[i] is the money in house i. Adjacent houses share an alarm, so you cannot rob two in a row.

Return the maximum amount you can rob.

Example 1

rob()
Input
nums = [1,2,3,1]
Output
4

Why

Rob house 0 and house 2.

Example 2

rob()
Input
nums = [2,7,9,3,1]
Output
12
Constraints
1 <= nums.length <= 100
0 <= nums[i] <= 400

Topics

Dynamic ProgrammingArrays

Implement rob in the editor and return the answer — printing it is never graded.