198. House Robber
All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : July 17, 2024
Last updated : July 17, 2024
Related Topics : Array, Dynamic Programming
Acceptance Rate : 51.64 %
class Solution:
def rob(self, nums: List[int]) -> int:
dp = [0, 0] + nums.copy()
for i in range(2, len(dp)) :
dp[i] = max(dp[i] + dp[i - 2], dp[i - 1])
return dp[-1]