[Easy]House Robber
来源:互联网 发布:淘宝商家开通花呗 编辑:程序博客网 时间:2024/05/29 17:28
问题:
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.
解法:
源码:
class Solution {public: int rob(vector<int>& nums) { int n = nums.size(); if (n == 0) return 0; int f[n][2]; f[0][0] = 0; f[0][1] = nums[0]; for (int i = 1; i < n; ++i) { f[i][0] = max(f[i-1][0], f[i-1][1]); f[i][1] = max(f[i-1][0] + nums[i], f[i-1][1]); } return max(f[n-1][0], f[n-1][1]); }};
0 0
- [Easy]House Robber
- 198. House Robber -Easy
- [Leetcode 198, Easy] House Robber
- <LeetCode><Easy> 198 House Robber
- 198. House Robber [easy] (Python)
- Easy 198题 House Robber
- 198. House Robber (Easy)
- 【Leetcode-Easy-198】House Robber
- LeetCode 198. House Robber (Easy)
- leetcode之旅-easy(House Robber)
- Easy-题目26:198. House Robber
- Leetcode 198. House Robber (Easy) (cpp)
- 198.leetcode House Robber(easy)[动态规划]
- (算法分析Week14)House Robber[Easy]
- leetcode 198 House Robber(难易度:Easy)
- [leetcode]House Robber 分享一个很easy的解法
- 198. House Robber 类别:动态规划 难度:easy
- 动态规划——198. House Robber[easy]
- 事件冒泡捕获及3个阶段
- [Medium]Number of Islands
- ZOrder
- 浏览器下载模板中文乱码
- HBase 原理
- [Easy]House Robber
- Pip源
- 文章标题
- JPA配置文档persistence.xml文件的参数说明
- [Medium]House Robber III
- [Medium]Best Time to Buy and Sell Stock II
- 盘点|回顾2016华为与交通行业的“最美旅程”
- 笔记——2
- 我的第一个java-web项目之路:(一)需求分析.