【easy】198. House Robber 123总结……

题目一:html

一个极其简单的动态规划。spa

class Solution { public: int rob(vector<int>& nums) { int best0 = 0;   // 表示没有选择当前houses 
        int best1 = 0;   // 表示选择了当前houses 
        for(int i = 0; i < nums.size(); i++){ int temp = best0; best0 = max(best0, best1); // 没有选择当前houses,那么它等于上次选择了或没选择的最大值 
            best1 = temp + nums[i];    // 选择了当前houses,值只能等于上次没选择的+当前houses的money 
 } return max(best0, best1); } };

 参考一个很好的blog:http://www.cnblogs.com/grandyang/p/4383632.htmlcode

题目二:造成环htm

参考一个很好的blog:https://www.cnblogs.com/grandyang/p/4518674.htmlblog

题目三:沿着二叉树偷的…一种看起来很厉害的偷法io

参考一个很好的blog:http://www.cnblogs.com/grandyang/p/5275096.htmlclass

相关文章
相关标签/搜索