House Robber II
Problem statement
Houses stand in a circle, and nums[i] is the nonnegative money in house i. The first and last houses are neighbors. Robbing two neighboring houses triggers an alarm.
Return the maximum total money you can rob without triggering an alarm. You may skip every house. With one house, you may rob that house once. Only the maximum amount matters, regardless of which optimal set achieves it.
Function
robCircular(nums: int[]) → intExamples
Example 1
nums = [2,3,2]return = 3The two houses holding two are adjacent around the circle, so only the middle house is optimal.
Example 2
nums = [1,2,3,1]return = 4Choose the houses holding one and three.
Example 3
nums = [0]return = 0The only house contains no money.
Constraints
1 <= nums.length <= 10^5.0 <= nums[i] <= 10^4.