package com.fishercoder.solutions;

/**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.
 */
public class _198 {

    public int rob(int[] nums) {
        if (nums == null || nums.length == 0) {
            return 0;
        }
        if (nums.length == 1) {
            return nums[0];
        }
        if (nums.length == 2) {
            return Math.max(nums[0], nums[1]);
        }
        int[] dp = new int[nums.length];
        dp[0] = nums[0];
        dp[1] = Math.max(nums[0], nums[1]);
        for (int i = 2; i < nums.length; i++) {
            dp[i] = Math.max(dp[i - 2] + nums[i], dp[i - 1]);
        }
        return dp[nums.length - 1];
    }

}

@@ -51,16 +51,17 @@
 Robber%0A%0A
+ 
 You are 
@@ -269,16 +269,17 @@
 security
+%0A
  system 
@@ -291,17 +291,16 @@
 cted and
-%0A
  it will
@@ -392,17 +392,17 @@
  night.%0A
-%0A
+ 
 Given a 
@@ -571,33 +571,407 @@
 ce.%0A
- */%0Apublic class _198 %7B%0A%0A
+%0A Example 1:%0A Input: %5B1,2,3,1%5D%0A Output: 4%0A Explanation: Rob house 1 (money = 1) and then rob house 3 (money = 3).%0A Total amount you can rob = 1 + 3 = 4.%0A%0A Example 2:%0A Input: %5B2,7,9,3,1%5D%0A Output: 12%0A Explanation: Rob house 1 (money = 2), rob house 3 (money = 9) and rob house 5 (money = 1).%0A Total amount you can rob = 2 + 9 + 1 = 12.%0A */%0Apublic class _198 %7B%0A%0A    public static class Solution1 %7B%0A    
     
@@ -999,32 +999,36 @@
 nums) %7B%0A        
+   
+ 
 if (nums == null
@@ -1059,24 +1059,28 @@
             
+    
 return 0;%0A  
@@ -1077,34 +1077,42 @@
 turn 0;%0A        
+  
-%7D%0A
+  %7D%0A    
         if (nums
@@ -1135,24 +1135,28 @@
             
+ 
+   
 return nums%5B
@@ -1151,32 +1151,36 @@
 return nums%5B0%5D;%0A
+    
         %7D%0A      
@@ -1173,32 +1173,36 @@
       %7D%0A        
+    
 if (nums.length 
@@ -1217,24 +1217,28 @@
             
+   
+ 
 return Math.
@@ -1268,26 +1268,32 @@
         
-%7D%0A
+    %7D%0A  
         
 int%5B%5D dp
@@ -1284,16 +1284,18 @@
         
+  
 int%5B%5D dp
@@ -1327,16 +1327,20 @@
         
+    
 dp%5B0%5D = 
@@ -1356,16 +1356,20 @@
         
+ 
+   
 dp%5B1%5D = 
@@ -1388,32 +1388,36 @@
 s%5B0%5D, nums%5B1%5D);%0A
+    
         for (int
@@ -1460,16 +1460,20 @@
         
+    
 dp%5Bi%5D = 
@@ -1514,34 +1514,42 @@
  - 1%5D);%0A        
+   
+ 
 %7D%0A
+    
         return d
@@ -1572,13 +1572,22 @@
 1%5D;%0A    
+    %7D%0A    
 %7D
-%0A
 %0A%7D%0A

refactor 198