Leetcode (H)
来源:互联网 发布:qq邮箱有没有mac版本 编辑:程序博客网 时间:2024/05/16 19:22
House Robber
Total Accepted: 3183 Total Submissions: 11595My SubmissionsYou 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> &num) { const int n = num.size(); if (n == 0) return 0; vector<int> rob(n); vector<int> no_rob(n); rob[0] = num[0], no_rob[0] = 0; for (int i = 1; i < n; ++i) { rob[i] = no_rob[i - 1] + num[i]; no_rob[i] = max(rob[i - 1], no_rob[i - 1]); } return max(rob[n - 1], no_rob[n - 1]); }};
0 0
- Leetcode (H)
- Leetcode 274 : H-index
- leetcode H-Index
- [leetcode][sort] H-Index
- 【leetCode】H-Index
- Leetcode: H-Index
- Leetcode: H-Index II
- leetcode 274: H-Index
- [leetcode] 274.H-Index
- leetcode 之 H-index
- LeetCode: H-Index
- leetcode H-index 2
- Leetcode: H-Index
- Leetcode: H-Index II
- leetcode: H-Index
- [LeetCode 274] H-index
- [LeetCode]H-Index
- [LeetCode]H-Index II
- java DES加密,解密算法实现
- OCP-1Z0-051 补充题库 第41题 nvl函数的使用
- Kafka入门
- mysql存储emoji表情,utf8mb4
- 使用Spring MVC统一异常处理实战
- Leetcode (H)
- Mac OS X 系统锁屏两种方式总结
- java字符串
- LibreOffice 生成VS2012工程
- 驾车线路导航api
- Linux平台下安装SSH
- WCF通讯方式之双向通讯
- HDFS dfsclient写文件过程 源码分析
- java 中的 final 变量