House Robber
Problem Given an array of non-negative integers where each element is the money in a house arranged in a line, find the maximum total you can rob without robbing two adjacent houses (adjacent robberies trigger the alarm).
Input / Output
- Input:
nums, a non-negative integer array. - Output: the maximum amount robbable with no two adjacent houses taken.
Constraints
- 0 <= nums.length; values are non-negative.
- Houses are in a straight line (the first and last are not adjacent).
Example
- [1,2,3,1] → 4 (rob houses 0 and 2).
- [2,7,9,3,1] → 12 (rob houses 0, 2, 4).
asked …