Given an array nums
where nums[i]
represents the money in the i-th house:
Return the maximum amount of money you can rob without alerting the police.
Constraints:
Examples:
// Example 1:
console.log(rob([1, 1, 3, 3]));
// Output: 4
// Explanation: Rob houses 0 and 2 (1 + 3 = 4)
// Example 2:
console.log(rob([2, 9, 8, 3, 6]));
// Output: 16
// Explanation: Rob houses 0, 2, and 4 (2 + 8 + 6 = 16)