You are given an integer array nums representing the amount of money in each house along a street. You cannot rob two adjacent houses.
Your task is to return the maximum amount of money you can rob without alerting the police.
Input: nums = [1,2,3,1]
Output: 4
Explanation: Rob house 0 (1) and house 2 (3) for a total of 4.
Input: nums = [2,7,9,3,1]
Output: 12
Explanation: Rob houses 0, 2, and 4 for a total of 2 + 9 + 1 = 12.
Input: nums = [5]
Output: 5
Explanation: With only one house, rob it for a total of 5.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
1 2 3 1
4
2 7 9 3 1
12
5 1 1 5
10