198. House Robber
来源:互联网 发布:淘宝推广有哪些渠道 编辑:程序博客网 时间:2024/05/21 14:47
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.
solution:
class Solution {public: int rob(vector<int>& nums) { int sz = nums.size(); if(sz == 0) return 0; if(sz == 1) return nums[0]; int a = nums[0]; int b = 0; int max_tmp = a; for(int i = 1; i<sz; i++){ a = b + nums[i]; b = max_tmp; max_tmp = max(a,b); } return max_tmp; }};心得:动态规划
运行速度:快
0 0
- 337. House Robber III+198. House Robber
- 198. House Robber&&213. House Robber II
- 198. House Robber && 213. House Robber II
- [LeetCode]198.House Robber
- 【LeetCode】198. House Robber
- 【LeetCode】198.House Robber
- LeetCode 198. House Robber
- 198.House Robber
- [leetcode] 198.House Robber
- [leetcode] 198. House Robber
- LeetCode:198. House Robber
- 198. House Robber LeetCode
- 198. House Robber
- [LeetCode]198. House Robber
- 198. House Robber
- LeetCode || 198. House Robber
- 198. House Robber
- LeetCode-198. House Robber
- nodejs资料
- Java反射知识
- 对IccCardStatus 的认识
- 域渗透前置知识
- 纯Java获得本机MAC地址
- 198. House Robber
- 四大组件-Activity
- Servlet和Android网络交互基础(1)
- Android HDMI CEC控制服务
- 跟踪系统性能(8)
- corosync+pacemaker+san实现web服务高可用
- 初识网络爬虫
- Factorial Trailing Zeroes
- 学习kotlin 记录笔记。----数据类型