Skip to content

Commit 33acd31

Browse files
committed
done
2 parents 48e6454 + 007bf21 commit 33acd31

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

dynamic_programming/house_robber.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,15 @@
1919
2020
"""
2121

22-
23-
24-
def rob(nums:list[int]) -> int:
22+
def rob(nums: list[int]) -> int:
2523
n = len(nums)
26-
if n < 3 :
24+
if n < 3:
2725
return max(nums)
28-
dp = [0]*n
26+
dp = [0] * n
2927
dp[0] = nums[0]
3028
dp[1] = max(nums[0], nums[1])
31-
for i in range(2,n):
32-
dp[i] = max(nums[i]+dp[i-2], dp[i-1])
29+
for i in range(2, n):
30+
dp[i] = max(nums[i] + dp[i - 2], dp[i - 1])
3331
return max(dp)
3432

3533

0 commit comments

Comments
 (0)