House Robber
A row of houses sits along a street, and nums[i] is the amount of cash hidden in house i. You want to steal as much as possible, but the security systems of adjacent houses are linked: robbing two houses that sit next to each other trips the alarm.
Return the maximum cash you can collect without ever robbing two adjacent houses.
Constraints: 1 <= nums.length <= 100 and 0 <= nums[i] <= 400.
Examples
- Input:
- nums = [1, 2, 3, 1]
- Output:
- 4
Rob house 0 (1) and house 2 (3): total 4. Robbing houses 1 and 3 gives only 3.
- Input:
- nums = [2, 7, 9, 3, 1]
- Output:
- 12
Rob houses 0, 2, and 4: 2 + 9 + 1 = 12. No adjacent pair is robbed.
Hints
One at a time — struggle first, peek second.
Your thinking space — verify on LeetCode, then mark it.