← 返回 meta 的题目列表House Robber
类型:online_judge
Given an integer array nums where nums[i] is the amount of money in the i-th house, you cannot rob two adjacent houses (if you rob i, you cannot rob i-1 or i+1).
Compute the maximum amount of money you can rob without triggering the alarm.
Input
One integer n, the number of houses.
One line with n integers, the array nums.
Output
A single integer: the maximum obtainable amount.
Constraints
1 <= n <= 1e5
0 <= nums[i] <= 1e9
Example
Input:
4
1 2 3 1
Output:
4
Explanation: Rob houses 1 and 3 (1 + 3 = 4).
Example
Input
4
1 2 3 1
Output
4