leetcode 198-House Robber
来源:互联网 发布:网络机顶盒能看外国台 编辑:程序博客网 时间:2024/05/29 03:56
难度:easy
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will automatically contact the police if two adjacent houses were broken into on the same night.
Given a list of non-negative integers representing the amount of money of each house, determine the maximum amount of money you can rob tonight without alerting the police.
思路:1. 打家劫舍,在不能同时打劫挨着的两家的情况下,求能偷到的最大金额。实质就是在一列数组中取出一个 或者多个不相邻的数,使其和最大,用到dp(动态规划,dynamic programming).动态规划算法通常基于 一个递推公式及一个或多个初始状态,当前子问题的解将有上一次子问题的解推出。最重要是根据最初的数据找到递推公式。
2. 此题中f[i]表示到第i家能偷窃到的最大钱数,f[0]=nums[0], f[1]=max(nums[0],nums[1]), f[2]=max(f[0]+nums[2].
3. 递推公式是:f[i]=max(f[i-2]+nums[i],f[i-1])
4. 写的不够简略
- Leetcode 198: House Robber
- leetcode-198 House Robber
- [LeetCode 198]House Robber
- House Robber - LeetCode 198
- leetcode 198 House Robber
- leetCode #198 House Robber
- LeetCode 198-House Robber
- Leetcode[198]-House Robber
- 【Leetcode】House Robber #198
- Leetcode 198 House Robber
- leetcode 198:House Robber
- House Robber (leetcode 198)
- 【LeetCode】198:House Robber
- leetcode[198]:House Robber
- leetcode-198-House Robber
- leetcode 198: House Robber
- [LeetCode 198]House Robber
- Leetcode# 198 House Robber
- 选修课程:光电显示技术概要(2017)
- synchronized 同步方法中静态与非静态的区别
- 古代荀子也懂AI?达芬奇的手术机器人有多神奇? 听浙大吴飞扒一扒人工智能的“古今中外”!
- 中断、异常与系统调用
- 二元分类中精确度precision和召回率recall的理解
- leetcode 198-House Robber
- 机器学习应该准备哪些数学预备知识?
- 【数据库】6数据备份还原,日志,性能优化
- 盘点记录自己学习过程中的难点,跳过的知识点
- java程序员的大数据之路(11):MapReduce的连接
- 使用python下载NCDC数据
- 图像处理-矩阵变换
- 关键字final在java中的运用
- 557. Reverse Words in a String III