LeetCode p198 Combinations 题解
1.题目:
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.
题意:
小偷偷东西的问题,输入一个数组,小偷不能偷相邻的两家,问小偷最多能偷多少钱。
2.解题思路:
dp..空间复杂度其实可以更小,但是这样容易理解一些。
递归公式见代码注释。
3.代码
1 |
|