Skip to content

Commit 689cc69

Browse files
committed
Update solution 198 [Python3]
1 parent 785e63b commit 689cc69

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

solution/198.House Robber/Solution.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution:
2+
def rob(self, nums):
3+
"""
4+
:type nums: List[int]
5+
:rtype: int
6+
"""
7+
length=len(nums)
8+
if length == 0:
9+
return 0
10+
if length == 1:
11+
return nums[0]
12+
res=[0]*length
13+
res[0]=nums[0]
14+
res[1]=max(nums[0],nums[1])
15+
16+
for i in range(2,length):
17+
res[i]=max(nums[i]+res[i-2],res[i-1])
18+
19+
return res[-1]

0 commit comments

Comments
 (0)