16 lines
433 B
Python
16 lines
433 B
Python
|
class Solution:
|
||
|
def rob(self, nums: list[int]) -> int:
|
||
|
s = []
|
||
|
rlt = -1e6
|
||
|
for i, num in enumerate(nums):
|
||
|
maxi = num
|
||
|
for j in range(0, i - 1, 1):
|
||
|
maxi = max(s[j] + num, maxi)
|
||
|
s.append(maxi)
|
||
|
rlt = max(maxi, rlt)
|
||
|
return rlt
|
||
|
|
||
|
sol = Solution()
|
||
|
print(sol.rob([1, 2, 3, 1]))
|
||
|
print(sol.rob([2, 7, 9, 3, 1]))
|
||
|
print(sol.rob([2, 7, 9, 9, 3, 1]))
|