1. Climbing Stairs
  2. House Robber

  3. House Robber II

  4. House Robber III

1. Climbing Stairs

Can use an array to store all numbers or just use a few variables to store the previous two steps since the current step number is based on the previous two step numbers.

3. House Robber II

dp + 去头去尾

由于新增的限制条件是首尾的两个房子不能被同时闯入,那么可以分别把首尾的房子去掉,长度变成n - 1,各算一遍最大的值,然后取较大值就可以了。这样的话,就可以重复利用house robber的答案了

4. House Robber III

https://leetcode.com/problems/house-robber-iii/discuss/79330/Step-by-step-tackling-of-the-problem

这个解释的非常好,step by step

results matching ""

    No results matching ""