Skip to content

Commit

Permalink
Merge pull request #599 from kjb512/main
Browse files Browse the repository at this point in the history
[kayden] Week 14 Solutions
  • Loading branch information
SamTheKorean authored Nov 17, 2024
2 parents eef72f2 + 437488c commit c2a2065
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
19 changes: 19 additions & 0 deletions binary-tree-level-order-traversal/kayden.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution:
# 시간복잡도: O(N)
# 공간복잡도: O(N)
def levelOrder(self, root: Optional[TreeNode]) -> List[List[int]]:
def traverse(node, level):
if not node:
return

if len(result) <= level:
result.append([])

result[level].append(node.val)

traverse(node.left, level + 1)
traverse(node.right, level + 1)

result = []
traverse(root, 0)
return result
14 changes: 14 additions & 0 deletions house-robber-ii/kayden.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution:
# 시간복잡도: O(N)
# 공간복잡도: O(1)
def rob(self, nums: List[int]) -> int:
if len(nums) == 1:
return nums[0]

def robLinear(houses: List[int]) -> int:
one, two = 0, 0
for money in houses:
one, two = two, max(two, one + money)
return two

return max(robLinear(nums[1:]), robLinear(nums[:-1]))
13 changes: 13 additions & 0 deletions reverse-bits/kayden.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Solution:
# 시간복잡도: O(1)
# 공간복잡도: O(1)
def reverseBits(self, n: int) -> int:
res = 0

for i in range(32):
bit = n & 1
n = n >> 1
res = res << 1
res = res | bit

return res

0 comments on commit c2a2065

Please sign in to comment.