Skip to content

Commit 10023d6

Browse files
authored
Merge pull request #1100 from aa601/main
[yeoju] Week 14
2 parents 7d1ef57 + 08e12f8 commit 10023d6

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

counting-bits/aa601.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'''
2+
TC: O(n)
3+
SC: O(n)
4+
'''
5+
class Solution:
6+
def countBits(self, n: int) -> List[int]:
7+
dp = [0] * (n + 1)
8+
for num in range(1, n + 1):
9+
dp[num] = dp[num // 2] + num % 2
10+
return dp

house-robber-ii/aa601.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'''
2+
TC : O(n)
3+
SC : O(1)
4+
'''
5+
class Solution:
6+
def rob(self, nums: List[int]) -> int:
7+
if len(nums) == 1:
8+
return nums[0]
9+
10+
def dp(start, end):
11+
prv, cur = 0, 0
12+
for idx in range(start, end):
13+
prv, cur = cur, max(prv + nums[idx], cur)
14+
return cur
15+
return max(dp(1, len(nums)), dp(0, len(nums) - 1))

0 commit comments

Comments
 (0)