← 返回 cisco 的题目列表House Robber
类型:online_judge
cisco
You are a professional robber planning to rob houses along a street. Each house has a certain amount of cash stamped as a non-negative integer array nums, but you cannot rob two adjacent houses.
Calculate the maximum profit possible.
Input Format:
A non-negative integer array nums representing the cash available at each house.
Output Format:
An integer representing the maximum profit.
Example 1:
Input: [1, 2, 3, 1] Output: 4 Explanation: Rob house 1 (cash = 1) and then rob house 3 (cash = 3), total profit = 1 + 3 = 4.
Example 2:
Input: [2, 7, 9, 3, 1] Output: 12 Explanation: Rob house 2 (cash = 2), rob house 4 (cash = 9), and rob house 5 (cash = 1), total profit = 2 + 9 + 1 = 12.
Example
Input
1 2 3 1\n