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;
    }
}

 

posted @ 2015-04-30 21:47  ~每天进步一点点~  阅读(144)  评论(0编辑  收藏  举报