classSolution {publicintrob(int[] nums) {if (nums.length==1) {return nums[0]; }returnMath.max(rob(nums,0,nums.length-2),rob(nums,1,nums.length-1) ); }privateintrob(int[] nums,int start,int end) {int dpi2 =0;int dpi1 =0;int dpi =0;for (int i = end; i >= start; i--) { dpi =Math.max(dpi1, nums[i] + dpi2); dpi2 = dpi1; dpi1 = dpi; }return dpi; }}/*so the range become different n n [x,x,x,x,x] n n3 cases to match questionsso we can only max(rob(1 ~ n-1),rob(1 ~ n)rob(0 ~ n-1))compare which one is biggerwe can ignore this one, rob(1 ~ n-1), this one must be smaller than other 2.*/