House Robber

public class Solution {
    public int rob(int[] nums) {
      int result=0;
      int rob=0;
      int unrob=0;
      for(int i=0;i<nums.length;i++){
          int temp=unrob;
          unrob=max(rob,unrob);
          rob=temp+nums[i];
          
      }
      return max(unrob,rob);
    }
    public int max(int a,int b){
       return a>b?a:b;
    }
}

 

你可能感兴趣的:(r)