public int rob(int[] nums) {
if (nums.length==0)
return 0;
return rob(nums.length1,nums);
}
public int rob(int i,int[] nums){
if(i==0){
return nums[0];
} else if(i==1){
return Math.max(nums[0],nums[1]);
} else{
return Math.max(rob(i1,nums),rob(i2,nums)+nums[i]);
}
}
//d(n)=max(d(n1),d(n2)+v(n))
//d(1)=v(1),d(2)=max(v(1),v(2))
I think my solution was DP, But I really don't understand why it is time limit exceeded


This is certainly not DP. This is just a recursive solution. DP implies saving smaller results to reuse them for getting bigger results. You just recalculate them instead, which leads to exponential complexity.
To make it DP you have to either memoize results in your solution (topdown DP) or use iterative bottomup approach.