public int rob(int[] nums) {
        int odd = 0, even = 0;
        for (int i = 0; i < nums.length; ++i) {
            if (i % 2 == 0) {
                even = Math.max(nums[i] + even, odd);
            } else {
                odd = Math.max(nums[i] + odd, even);
            }
        }
        return Math.max(odd, even);
    }