LEETCODE--House Robber
2016-01-31 21:58
429 查看
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.
“`
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 length = nums.size(); if(length == 0){ return NULL; } int arr[length]; arr[0] = nums[0]; arr[1] = max(nums[0], nums[1]); for(int i = 2; i < length; i++){ arr[i] = max((nums[i]+arr[i-2]), arr[i-1]); } return arr[length-1]; } };
“`
相关文章推荐
- PriorityQueue源码解析
- HDU 1560 DNA sequence(IDA*搜索)
- 再谈PHP、Python与Ruby
- 4.windows和Linux下创建oracleusername表空间,表,插入数据,用户管理表等操作
- Divide and conquer:Subset(POJ 3977)
- Ubuntu彻底删除mysql
- BZOJ-1050 旅行comf 并查集+乱搞
- 2016年1月英语总结
- hdu 2113 Secret Number
- 算法题汇总
- Mina的使用
- BZOJ-1050 旅行comf 并查集+乱搞
- 【HDOJ】4393 Throw nails
- Singleton 单例模式(懒汉方式和饿汉方式)
- 机器学习入门资源不完全汇总
- 面向对象的基础
- Mac 下用 go 开发Android应用环境设置
- angularjs项目下的gulp配置(一)
- 初级文法课程-第1课:名词的种类/名词的数/名词的所有格/冠词;be 动词、一般动词的现在式
- hdu 5616