###### Authentic Preference

Technologies come and technologies go, but insight is forever.

### 原题

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.

### 代码分析

        //nums = {1, 8, 12 10, 9 }
public int Rob(int[] nums)
{
int inCur = 0; //偷当前房子能获取的最大钱数
int noInCur = 0;//不偷当前的房子能收获的最大钱数
for (int i = 0; i < nums.Length; i++)
{
int tmp = nums[i]+ noInCur; //偷 ith 房子，上一个房子就不能偷
noInCur = Math.Max(inCur, noInCur); //如果不偷 ith 房子，则noInCur 等于偷 i-1 房子和不偷 i-1 房子的最大值
inCur = tmp; //偷当前房子后的获取总钱数
}
return Math.Max(inCur, noInCur);
}


### leetcode-solution库

leetcode算法题目解决方案每天更新在github库中，欢迎感兴趣的朋友加入进来，也欢迎star，或pull request。https://github.com/jackzhenguo/leetcode-csharp

#### leetCode198-House Robber

2015-04-01 18:28:58

#### Leetcode 198: House Robber

2015-04-01 02:51:09

#### 198. House Robber [easy] (Python)

2016-06-01 14:39:22

#### 198. House Robber Leetcode Python

2015-03-31 22:28:07

#### Leetcode_198_House Robber

2015-08-15 12:02:28

#### 【LeetCode-面试算法经典-Java实现】【198-House Robber（抢劫犯）】

2015-08-25 06:41:25

#### LeetCode 198 House Robber 打家劫舍

2016-04-14 10:16:29

#### Dynamic Programming:198. House Robber

2017-09-28 19:39:48

#### [leetcode] 337. House Robber III

2016-03-12 20:20:56

#### [leetcode-337]House Robber III(java)

2016-03-27 22:19:41

## 不良信息举报

LeetCode-Easy部分中标签为Dynamic Programming *198. House Robber