question: public int rob ( int [ ] nums ) { if ( nums == null || nums . length == 0 ) return 0 ; if ( nums . length == 1 ) return nums [ 0 ] ; int preMax = nums [ 0 ] ; int max = Math . max ( nums [ 0 ] , nums [ 1 ] ) ; for ( int i = 2 ; i < nums . length ; i ++ ) { int temp = preMax ; preMax = max ; max = Math . max ( temp + nums [ i ] , preMax ) ; } return max ; }
target:  Recurrence relation: max[n] = max(max[n - 2] + nums[n], max[n - 1]) Optimization: use constant variables instead of an array