We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 84335f1 commit 0f2057eCopy full SHA for 0f2057e
house-robber-ii/Leo.py
@@ -0,0 +1,16 @@
1
+class Solution:
2
+ def rob(self, nums: List[int]) -> int:
3
+ n = len(nums)
4
+ if n == 1:
5
+ return nums[0]
6
+
7
+ def robrob(nums):
8
+ rob1, rob2 = 0, 0
9
+ for i in range(len(nums)):
10
+ rob1, rob2 = rob2, max(nums[i] + rob1, rob2)
11
12
+ return rob2
13
14
+ return max(robrob(nums[:n - 1]), robrob(nums[1:]))
15
16
+ ## TC: O(n), SC: O(1)
house-robber/Leo.py
@@ -0,0 +1,10 @@
+ rob, not_rob = 0, 0
+ for i in nums:
+ rob, not_rob = not_rob + i, max(rob, not_rob)
+ return max(rob, not_rob)
0 commit comments