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.
1 parent 5bd16bd commit 230a1feCopy full SHA for 230a1fe
leetcode.com 198. House Robber v2/main.py
@@ -0,0 +1,13 @@
1
+from typing import List
2
+
3
4
+class Solution:
5
+ def rob(self, nums: List[int]) -> int:
6
+ nums = [0, 0, 0] + nums
7
+ dp = [0 for _ in range(len(nums))]
8
9
+ for idx in range(3, len(nums)):
10
+ mx = max(dp[idx - 3], dp[idx - 2])
11
+ dp[idx] = mx + nums[idx]
12
13
+ return max(dp)
leetcode.com 198. House Robber v2/test_main.py
@@ -0,0 +1,16 @@
+from unittest import TestCase
+from main import Solution
+class TestSolution(TestCase):
+ def test1_rob(self):
+ sln = Solution()
+ self.assertEqual(
+ 4, sln.rob([1,2,3,1])
+ )
+ def test2_rob(self):
14
15
+ 12, sln.rob([2,7,9,3,1])
16
0 commit comments