[198] house robber

leetcode

this is an easy problem.
** first recursion **

dp[i] = max(dp[i - 1], dp[i - 2] + num[i]

** second recursion **

dp[i][0] -- house i not rob
dp[i][1] -- house i rob

dp[i][0] = max(dp[i - 1][[0], dp[i - 1][1])
dp[i][1] = dp[i - 1][0] + num[i]

** can use rolling array to optimize the memory.**

你可能感兴趣的:([198] house robber)