LeetCode 198, 213 House Robber

Posted 約束の空

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode 198, 213 House Robber相关的知识,希望对你有一定的参考价值。

198 House Robber

DP

0~n-1     ans=dp[n-1]

dp[i] = max(dp[i-2]+nums[i], dp[i-1])  i>=2

 

 

213 House Robber II

Since we cannot rob nums[0] and nums[n-1] at the same time, we can divide this problem into two cases:

not rob nums[0]

not rob nums[n-1]

and the answer is the maximum one.

C++ stl vector可以用 vector<int> nums1(nums.begin(), nums.end())来初始化 比较实用

以上是关于LeetCode 198, 213 House Robber的主要内容,如果未能解决你的问题,请参考以下文章

House Robbers. 198 & 213

LeetCode 198. House Robber

leetcode 198. House Robber 打家劫舍(中等)

leetCode 198. House Robber | 动态规划

LeetCode 198. House Robber

Leetcode 198 House Robber