• 33.4%

https://leetcode.com/problems/house-robber-ii/#/description

Note: This is an extension of House Robber.

After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. This time, all houses at this place are arranged in a circle. That means the first house is the neighbor of the last one. Meanwhile, the security system for these houses remain the same as for those in the previous street.

Given a list of non-negative integers representing the amount of money of each house, determine the maximum amount of money you can rob tonight without alerting the police.

https://discuss.leetcode.com/topic/14504/9-lines-0ms-o-1-space-c-solution

9-lines 0ms O(1)-Space C++ solution

This problem is a little tricky at first glance. However, if you have finished the House Robber problem, this problem can simply be decomposed into two House Robber problems.
Suppose there are n houses, since house 0 and n - 1 are now neighbors, we cannot rob them together and thus the solution is now the maximum of

1. Rob houses 0 to n - 2;
2. Rob houses 1 to n - 1.

The code is as follows. Some edge cases (n < 2) are handled explicitly.

https://discuss.leetcode.com/topic/14325/twice-pass-solution-c

Twice pass solution, C++

Twice pass:

not rob nums[n-1]

not rob nums[0]

and the other is same as House Robber.

https://discuss.leetcode.com/topic/20770/c-super-simple-0ms-solution-with-explanation

[C++] Super Simple 0ms solution with explanation

Since you cannot rob both the first and last house, just create two separate vectors, one excluding the first house, and another excluding the last house. The best solution generated from these two vectors using the original House Robber DP algorithm is the optimal one.

https://discuss.leetcode.com/topic/18123/0ms-o-n-time-o-1-space-c-solution

0ms O(N) time O(1) space C++ solution

This solution is based on house robber 1. The idea is that either the first house or the last house is not robbed. The final solution is max of (house robber without last element) and (house robber without the first element). Note endIndex is not inclusive in the second rob function.

https://discuss.leetcode.com/topic/28279/simple-and-easy-c-solution-modified-from-the-best-solution-of-house-robber-easy

Simple and easy C++ solution modified from the best solution of House Robber (Easy)