@@ -0,0 +1,1560 @@
+//You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed,%0A// the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and%0A// it will automatically contact the police if two adjacent houses were broken into on the same night.%0A//%0A// Given a list of non-negative integers representing the amount of money of each house,%0A// determine the maximum amount of money you can rob tonight without alerting the police.%0Apackage org.leituo.leetcode.dp;%0A%0A/**%0A * Created by leituo56 on 3/31/15.%0A */%0Apublic class HouseRobber %7B%0A    // %E6%8A%A2%E4%B8%80%E4%B8%B2%E6%88%BF%E5%AD%90%EF%BC%8C%E7%9F%A5%E9%81%93%E6%88%BF%E5%AD%90%E9%87%8C%E6%9C%89%E5%A4%9A%E5%B0%91%E9%92%B1%EF%BC%8C%E4%B8%A4%E4%B8%AA%E6%8C%A8%E7%9D%80%E7%9A%84%E6%88%BF%E5%AD%90%E8%A2%AB%E6%8A%A2%E5%B0%B1%E4%BC%9A%E6%8A%A5%E8%AD%A6%EF%BC%8C%E6%B1%82%E8%83%BD%E6%8A%A2%E7%9A%84%E6%9C%80%E5%A4%A7%E9%92%B1%E6%95%B0%0A    class Solution %7B%0A        // use dp, store the max gold robbin until x.%0A        // dp%5Bx%5D = max(dp%5Bx-2%5D + num%5Bx%5D, dp%5Bx-1%5D)%0A        // return the last elem of dp%0A        // can write concise with only two temp var indead of dp%5B%5D, 2 to left and 1 to left%0A        public int rob(int%5B%5D num) %7B%0A            if(num == null %7C%7C num.length == 0)%0A                return 0;%0A            if(num.length == 1)%0A                return num%5B0%5D;%0A            int pre = num%5B0%5D;//max gold robbed till 2 left to cur%0A            int adj = Math.max(num%5B0%5D, num%5B1%5D);//max gold robbed till 1 left to cur%0A            for(int i = 2; i %3C num.length; i++)%7B%0A                int op1 = pre + num%5Bi%5D;//option 1, choose cur + 2 to left%0A                int op2 = adj;//option 2, just choose left%0A                pre = adj;%0A                adj = Math.max(op1, op2);%0A            %7D%0A            return adj;%0A        %7D%0A    %7D%0A%7D%0A

lc new question, rob houses