Skip to content

Latest commit

 

History

History
23 lines (22 loc) · 675 Bytes

198. House Robber.md

File metadata and controls

23 lines (22 loc) · 675 Bytes

Solution1 (dp)

class Solution {
    public int rob(int[] nums) {
        if (nums == null || nums.length == 0) {
            return 0;
        }
        int prev1 = 0;
        int prev2 = 0;
        for (int num : nums) {
            int temp = Math.max(num + prev1, prev2);
            prev1 = prev2;
            prev2 = temp;
        }
        return prev2;
    }
}

note