Q198. House Robber
Last updated
Was this helpful?
Last updated
Was this helpful?
直达:
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will automatically contact the police if two adjacent houses were broken into on the same night.
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.
Credits: Special thanks tofor adding this problem and creating all test cases. Also thanks tofor adding additional test cases.
动态规划的经典题目,动态规则也非常简单。第i天盗得的总和是第i-2天,或者第i-3天最大值加上nums[i], 所以有动态规划更新规则:
注:为了编码方便,动态规划数组添加了一个0的头。