# 198. House Robber

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.

Credits:
Special thanks to @ifanchu for adding this problem and creating all test cases. Also thanks to @ts for adding additional test cases.

1. 假如有3家，如果抢了第1家，就不能抢第2家，然后一定抢第3家，这时候比较第2家和第1家、第3家的钱的和的大小。

2. 假如有4家，抢了第1家，第2家不能抢，这时候如果抢第3家，则需要与第二家、第4家的和比较大小，如果是抢第四家，则需要将第1、4家的和与第2、3家的最大值比较大小。

（注意前一步的i和e，这就是为什么我们使用tmp在这里存储以前的i时计算e，使O（1）空间）

class Solution {
public int rob(int[] num) {
int i = 0;
int e = 0;
for (int k = 0; k<num.length; k++) {
int tmp = i;
i = num[k] + e;
e = Math.max(tmp, e);
}
return Math.max(i,e);
}
}
09-04