Exemple #1
0
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:]))
Exemple #2
0
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
Exemple #3
0
 def test_case_1(self):
     self.assertEqual(rob([1, 2, 3, 1]), 4)
Exemple #4
0
 def test_case_2(self):
     self.assertEqual(rob([2, 1, 1, 2]), 4)
Exemple #5
0
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:]))