题目链接Leetcode_198. 打家劫舍关键词{% label 动态规划 green %}、{% label 数组 blue %}解析dp[i]: 表示偷到第i家的最高金额偷第 i 家:dp[i] = dp[i - 2] + nums[i]不偷第 i 家:dp[i] = dp[i - 1]根据 dp[i] 的定义,则 dp[i] = Math.max(dp[i - 2] + nums[i - 2], dp[i - 1])为了方便下标,可以把 dp[] 的前两位空出来,就可以不用考虑下标越界的问题了代码相似题目Leetcode_213. 打家劫舍 IIAuthor:CoderWddURL:https://www.wuinsights.top//article/e493ddc688ccCopyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!Relate PostsLeetcode 2923. 找到冠军 ILeetcode1026. 节点与其祖先之间的最大差值Leetcode 1702. 修改后的最大二进制字符串Leetcode 894. 所有可能的真二叉树Leetcode_64-最小路径和Leetcode_907-子数组的最小值之和View dispatchTouchEventLeetcode_121.买卖股票的最佳时机