We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 48e6454 + 007bf21 commit 33acd31Copy full SHA for 33acd31
1 file changed
dynamic_programming/house_robber.py
@@ -19,17 +19,15 @@
19
20
"""
21
22
-
23
24
-def rob(nums:list[int]) -> int:
+def rob(nums: list[int]) -> int:
25
n = len(nums)
26
- if n < 3 :
+ if n < 3:
27
return max(nums)
28
- dp = [0]*n
+ dp = [0] * n
29
dp[0] = nums[0]
30
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])
+ for i in range(2, n):
+ dp[i] = max(nums[i] + dp[i - 2], dp[i - 1])
33
return max(dp)
34
35
0 commit comments