Dynamic programming, let dp[i][0] represent the maximum value without selecting nums[i], dp[i][1] represent the maximum value with selecting nums[i], then:
classSolution { public: introb(vector<int> &nums) { int i, n = nums.size();
// vector<int> dp(n); // dp[i][0] represents the maximum amount without robbing i // dp[i][1] represents the maximum amount with robbing i // dp[i][0] = max{dp[i-1][0], dp[i-1][1]} // dp[i][1] = dp[i-1][0] + nums[i]