**LeetCode-House Robber

DP 题 

想不清楚怎么做 需要再刷几道,这个的prevno prevyes分别是如何得来的 需要搞清楚

public class Solution {
    public int rob(int[] nums) {
        int prevNo = 0;
        int prevYes = 0;
        for ( int i = 0; i < nums.length; i ++ ){
            int temp = prevNo;
            prevNo = Math.max( prevNo, prevYes );
            prevYes = temp + nums[ i ];
        }
        return Math.max( prevNo, prevYes );
    }
}


你可能感兴趣的:(**LeetCode-House Robber)