public int rob(int[] nums) {

		int n = nums.length;
		if (n == 0)
			return 0;
		if (n == 1)
			return nums[0];
		if (n == 2)
			return Math.max(nums[0], nums[1]);

		int[] ret1 = new int[n];
		int[] ret2 = new int[n];

		ret1[0] = nums[0];
		ret1[1] = Math.max(nums[0], nums[1]);
		int m = n - 1; // optimized code by not count in loop condition
		for (int i = 2; i < m; i++) {
			int cur = nums[i];
			ret1[i] = Math.max(ret1[i - 2] + cur, ret1[i - 1]);
		}

		ret2[1] = nums[1];
		ret2[2] = Math.max(nums[1], nums[2]);
		for (int i = 3; i < n; i++) {
			int cur = nums[i];
			ret2[i] = Math.max(ret2[i - 2] + cur, ret2[i - 1]);
		}

		return Math.max(ret1[n - 2], ret2[n - 1]);
	}