MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / Solution

Class Solution

DP/HouseRobber.py:51–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49
50"""
51class Solution(object):
52 def rob(self, nums):
53 """
54 :type nums: List[int]
55 :rtype: int
56 """
57 if not nums:
58 return 0
59
60 if len(nums) <= 2:
61 return max(nums)
62
63 robber = [nums[0], nums[1], nums[2] + nums[0]]
64
65 for i in range(3, len(nums)):
66 robber.append(max(nums[i] + robber[i-2], nums[i] + robber[i-3]))
67
68 return max(robber)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected