题目
法1:DP
class Solution {public int rob(int[] nums) {int n = nums.length;if (n == 1) {return nums[0];}if (n == 2) {return Math.max(nums[0], nums[1]);}int pre0 = nums[0], pre1 = Math.max(nums[0], nums[1]), max = 0;for (int i = 2; i < n; ++i) {max = Math.max(pre0 + nums[i], pre1);pre0 = pre1;pre1 = max;}return max;}
}