← 返回 amazon 的题目列表House Robber
类型:online_judge
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, and adjacent houses have security alarms connected. If two adjacent houses are broken into on the same night, the alarm will be triggered. Given a list of non-negative integers representing the amount of money of each house, determine the maximum amount of money you can rob tonight without alerting the police.
Input
nums: A list of non-negative integers representing the money of each house. 1 <= nums.length <= 100, 0 <= nums[i] <= 400.
Output
Maximum amount of money you can rob.
Example
Example 1:
Input: [1, 2, 3, 1]
Output: 4
Explanation: Rob house 1 and 3.
Example 2:
Input: [2, 7, 9, 3, 1]
Output: 12
Explanation: Rob house 2 and 4.
Example
Input
[1, 2, 3, 1]