美文网首页
[198] house robber

[198] house robber

作者: 秋_轩 | 来源:发表于2016-12-31 12:14 被阅读0次

    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

          本文链接:https://www.haomeiwen.com/subject/ofivvttx.html