198 House robber
https://leetcode.com/problems/house-robber/
class Solution {
public int rob(int[] nums) {
int maxPrev = 0;
int max = nums[0];
for (int i = 1; i < nums.length; i++) {
int current = Math.max(max, maxPrev+nums[i]);
maxPrev = max;
max = current;
}
return max;
}
}Last updated