def rob(numbers: List[int]) -> int: """https://leetcode.com/problems/house-robber-ii/""" n = len(numbers) if n == 1: return house_robber.rob(numbers) return max(house_robber.rob(numbers[:n - 1]), house_robber.rob(numbers[1:]))
def test_rob(): assert rob([]) == 0 assert rob([1]) == 1 assert rob([1, 2]) == 2 assert rob([1, 2, 3]) == 4 assert rob([1, 2, 3, 1]) == 4 assert rob([2, 1, 1, 2]) == 4 assert rob([2, 7, 9, 3, 1]) == 12 assert rob([4, 1, 2, 7, 5, 3, 1]) == 14
def test_case_1(self): self.assertEqual(rob([1, 2, 3, 1]), 4)
def test_case_2(self): self.assertEqual(rob([2, 1, 1, 2]), 4)
def rob_circular(house_list): if len(house_list) == 1: return house_list[0] return max(rob(house_list[0:-1]), rob(house_list[1:]))