House Robber
Problem statement
You are given an array nums, where nums[i] is the amount of money in house i.
Adjacent houses cannot both be robbed. Return the maximum total amount that can be robbed without choosing two adjacent houses.
Function
rob(nums: int[]) → intExamples
Example 1
nums = [1,2,3,1]return = 4Rob houses 0 and 2 for 1 + 3 = 4.
Example 2
nums = [2,7,9,3,1]return = 12Rob houses 0, 2, and 4 for 2 + 9 + 1 = 12.
Example 3
nums = [5]return = 5The only house can be robbed.
Constraints
1 <= nums.length <= 100.0 <= nums[i] <= 400.