题目一:

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

class Solution {
public:
int rob(vector<int>& nums) {
int best0 = ; // 表示没有选择当前houses
int best1 = ; // 表示选择了当前houses
for(int i = ; 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.html

题目二:形成环

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

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

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

【easy】198. House Robber 123总结……的更多相关文章

  1. 198. House Robber,213. House Robber II

    198. House Robber Total Accepted: 45873 Total Submissions: 142855 Difficulty: Easy You are a profess ...

  2. 198. House Robber(动态规划)

    198. House Robber You are a professional robber planning to rob houses along a street. Each house ha ...

  3. leetcode 198. House Robber 、 213. House Robber II 、337. House Robber III 、256. Paint House(lintcode 515) 、265. Paint House II(lintcode 516) 、276. Paint Fence(lintcode 514)

    House Robber:不能相邻,求能获得的最大值 House Robber II:不能相邻且第一个和最后一个不能同时取,求能获得的最大值 House Robber III:二叉树下的不能相邻,求能 ...

  4. (easy)LeetCode 198.House Robber

    You are a professional robber planning to rob houses along a street. Each house has a certain amount ...

  5. leetcode 198. House Robber (Easy)

    https://leetcode.com/problems/house-robber/ 题意: 一维数组,相加不相邻的数组,返回最大的结果. 思路: 一开始思路就是DP,用一维数组保存dp[i]保存如 ...

  6. [LeetCode] 198. House Robber 打家劫舍

    You are a professional robber planning to rob houses along a street. Each house has a certain amount ...

  7. 【LeetCode】198. House Robber 打家劫舍 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 递归 + 记忆化 动态规划 优化动态规划空间 ...

  8. Leetcode 198 House Robber

    You are a professional robber planning to rob houses along a street. Each house has a certain amount ...

  9. Java for LeetCode 198 House Robber

    You are a professional robber planning to rob houses along a street. Each house has a certain amount ...

随机推荐

  1. python_while

    while 格式 while 条件 : pass 使用 while True : print("精忠报国") print("粉红的回忆") print(&quo ...

  2. js 简单弹框toast

    新建toast.js文件 function Toast(msg,duration){ duration=isNaN(duration)?3000:duration; var m = document. ...

  3. 【学习总结】GirlsInAI ML-diary day-19-面向对象编程

    [学习总结]GirlsInAI ML-diary 总 原博github链接-day19 认识面向对象 Python使用类(class)和对象(object),进行面向对象(object-oriente ...

  4. 判定你的java应用是否正常(是否内存、线程泄漏)的一个简单方法

    给大家推荐一个最简单的判定你的java应用是否正常的方法: step1:部署你的应用,让它跑起来: step2:打开jdk下bin目录下的jconsole.exe工具,连接到你的应用——以监测线程和内 ...

  5. tp5问题整理

    问题一:致命错误: Class 'think\controller' not found 原因:controller首字母要大写 解决:use think\Controller; 问题二:html页面 ...

  6. Java8 list转map 坑

    Map<String , SonCargosForm> orderCargosMap = sonTemporaryForm.getOrderCargosList().stream() .c ...

  7. aop 幂等验证(二)

    1 创建IIdempotent @Target({ElementType.PARAMETER, ElementType.METHOD}) @Retention(RetentionPolicy.RUNT ...

  8. python3.7安装pylint

    python3.7安装pylint之"setuptools"版本错误 借鉴:错题集(已解决):pyinstaller报错ModuleNotFoundError: No module ...

  9. canvas基础(一)

    获取元素与画笔: <canvas id="myCanvas" width="200" height="200">该浏览器不支持c ...

  10. maven私服nexus清理释放磁盘空间

    应用背景: 自建的maven私服(或者叫私仓)nexus在使用过程中,因很多服务不断迭代更新上传jar包至nexus中,底层存放在一个叫Blob Stores的存储中,最近发现该存储已增大至好几百G, ...