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 8fefbeb commit 7507b00Copy full SHA for 7507b00
house-robber-ii/hu6r1s.py
@@ -0,0 +1,12 @@
1
+class Solution:
2
+ def rob(self, nums: List[int]) -> int:
3
+ return max(nums[0], self.helper(nums[1:]), self.helper(nums[:-1]))
4
+
5
6
+ def helper(self, nums):
7
+ rob1, rob2 = 0, 0
8
+ for num in nums:
9
+ new_rob = max(rob1 + num, rob2)
10
+ rob1 = rob2
11
+ rob2 = new_rob
12
+ return rob2
0 commit comments