House Robber
来源:互联网 发布:钢铁力量狐狸升级数据 编辑:程序博客网 时间:2024/04/30 00:05
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 andit 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 tonightwithout alerting the police
class Solution {public: int rob(vector<int> &num) { int n = num.size(); if (n < 1) { return 0; } if (n == 1) { return num[0]; } int buf[n]; int maxTable[n]; buf[0] = num[0]; maxTable[0] = num[0]; buf[1] = num[1]; maxTable[1] = max(buf[0], buf[1]); for (int i = 2; i < n; i++) { buf[i] = maxTable[i-2] + num[i]; maxTable[i] = max(maxTable[i-1], buf[i]); } return maxTable[n-1]; }};
.
0 0
- House Robber
- House Robber
- House Robber
- House Robber
- House Robber
- House Robber
- House Robber
- House Robber
- House Robber
- House Robber
- House Robber
- House Robber
- House Robber
- House Robber
- House Robber
- House Robber
- House Robber
- House Robber
- 追加写入的方式的 写 csv文件
- Zend Framework2中的Zend\Db\Adapter分析和应用
- 欢迎使用CSDN-markdown编辑器
- mac install pip
- 让Redis在你的系统中发挥更大作用的几点建议
- House Robber
- URAL - 1793 Tray 2(几何题)
- poj 1679 The Unique MST(次小生成树)
- 关于Java性能的9个谬论
- codevs均分纸牌 贪心算法
- 比较两个XML节点编号---轻开平台(原WebEasy)字符串计算5
- 什么是Java内存模型
- QPushButton 文字居左
- Java开源软件六大帮派