Skip to content

Commit 7507b00

Browse files
committed
feat: Solve house-robber-ii problem
1 parent 8fefbeb commit 7507b00

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

house-robber-ii/hu6r1s.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)