198 给定一个数组 找到子序列的和的最大值 但是必须要求这个序列所有的值不能连在一起
很简单

class Solution {
    public int rob(int[] nums) {
        if (nums == null || nums.length == 0) {
            return 0;
        }
        int m = nums.length;
        int[] dp = new int[m];
        //dp[i] represents for the max we can get if we only have first i 
        //dp[i] = Math.max(dp[i-1], dp[i-2] + nums[i]);
        if (m == 1) return nums[0];
        if (m == 2) return Math.max(nums[0], nums[1]);
        dp[0] = nums[0];
        dp[1] = Math.max(nums[0], nums[1]);
        for (int i = 2; i < m; i++) {
            dp[i] = Math.max(dp[i-1], dp[i-2]+nums[i]);
        }
        return dp[m-1];
        
    }
}

213 现在所有的房子成了一个环形
because that we used to have our own choice about whether we should rob the first house, but now, if we rob the first house then we can’t rob the last. so the current problem will divided into two smaller problems: rob the first but not the last, and rob the last but not the first.
so for the house that we are not gonna rob, it doesn’t matter if it exists or not, so the problem divided into:
rob(num) = Math.max(rob(num,0, len-2), rob(num, 1, rob-1));
and the rob method is exactly the same as LC198.