198. House Robber
2016-02-22 16:37
363 查看
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:
运行速度:快
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; } };心得:动态规划
运行速度:快
相关文章推荐
- 域渗透前置知识
- UITableView
- Tokyo Tyrant(TTServer)系列(三)-Memcache协议
- Asp.net 文件进行二进制转码 解码
- Memcached 基础了解
- Python java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory解决办法
- Shell 自定义颜色输出函数
- JDK自带的日志Logging
- 关于自定义dialog不能左右全屏的解决办法
- tty、pty、pts含义
- (int)(a - b)并不安全,其中a和b均为unsigned int
- JDK自带的日志Logging
- HDU 3037 Saving Beans(Lucas定理的直接应用)
- 《Java程序设计》第四章-认识对象
- python+mysql抓取百度新闻的标题存到数据库
- quagga线程机制概述
- corosync+pacemaker+drbd实现web服务高可用
- dataTables-使用详细说明整理
- PeekInputStream
- hive安装配置与hive的JDBC (hadoop-0.20.2 + hive-0.7.0)