class Solution(object): def rob(self, nums): """ :type nums: List[int] :rtype: int """ if len(nums) == 1: return nums m_low = m_high = 0 for n in nums: # first round m_high, m_low = max(m_low + n, m_high), m_high first_round = m_high for n in nums: # second round m_high, m_low = max(m_low + n, m_high), m_high return m_high - first_round
The problem can be treated equivalent as the problem
House Robber I, but the input is a list from the list joined with a copy of itself.
(1,2,...,n,1,2,..n). and just return the money from the second half.