@@ -0,0 +1,1167 @@
+/**%0A *%09You are a professional robber planning to rob houses along a street. %0A *%09Each house has a certain amount of money stashed, the only constraint stopping you %0A *%09from robbing each of them is that adjacent houses have security system connected %0A *%09and it will automatically contact the police if two adjacent houses were %0A *%09broken into on the same night.%0A *%0A *%09Given a list of non-negative integers representing the amount of money of each house, %0A *%09determine the maximum amount of money you can rob tonight without alerting the police.%0A *%0A *%09Author: matao%0A *%0A */%0A%0Apublic class HouseRobber %7B%0A%09// f%5Bi%5D = max%7Bf%5Bi-2%5D + nums%5Bi%5D, f%5Bi-1%5D%7D%0A%09public static int rob(int%5B%5D nums) %7B%0A%09%09int n = nums.length;%0A%09%09int%5B%5D f = new int%5Bn%5D;%0A%09%09if (n == 1) %7B%0A%09%09%09f%5B0%5D = nums%5B0%5D;%0A%09%09%7D%0A%09%09if(n %3E= 2) %7B%0A%09%09%09f%5B1%5D = f%5B0%5D %3E nums%5B1%5D ? f%5B0%5D : nums%5B1%5D;%0A%09%09%7D%0A%09%09for (int i = 2; i %3C nums.length; i++) %7B%0A%09%09%09f%5Bi%5D = f%5Bi - 1%5D %3E f%5Bi - 2%5D + nums%5Bi%5D ? f%5Bi - 1%5D : f%5Bi - 2%5D + nums%5Bi%5D;%0A%09%09%7D%0A%09%09return f%5Bn - 1%5D;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A    %09int%5B%5D nums1 = %7B1, 1, 2, 3, 5%7D;%0A    %09int%5B%5D nums2 = %7B2, 1, 0, 2, 4%7D;%0A    %09System.out.println(rob(nums1));%0A    %09System.out.println(rob(nums2));%0A    %7D%0A%7D

add House Robber solution