LeetCode 198 House Robber
概述
https://leetcode.com/problems/house-robber/
动态规划问题
class Solution {
public:
vector<int> dp;
int rob(vector<int>& nums) {
dp.resize(nums.size(), -1);
return helper(nums, 0);
}
int helper(vector<int>& nums, int i) {
if (i >= nums.size()) return 0;
if (dp[i] != -1) return dp[i];
dp[i] = max(nums[i] + helper(nums, i+2), helper(nums, i+1));
return dp[i];
}
};
Links: leetcode-198-house-robber