From 3fa38c59142d99e54336daa63334a8b340e19304 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Tue, 22 Sep 2026 21:31:19 +0900 Subject: [PATCH 1/3] counting bits solution --- counting-bits/yuseok89.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 counting-bits/yuseok89.py diff --git a/counting-bits/yuseok89.py b/counting-bits/yuseok89.py new file mode 100644 index 0000000000..17406fa2ba --- /dev/null +++ b/counting-bits/yuseok89.py @@ -0,0 +1,17 @@ +# TC: O(N) +# SC: O(N) +class Solution: + def countBits(self, n: int) -> list[int]: + ans = [] + + upper = 1 + ans.append(0) + + for idx in range(1, n + 1): + ans.append(ans[idx - upper] + 1) + + if idx == upper: + upper *= 2 + + return ans + From 3f32f3883d8af9bef65a56c341cbdf69fff03ce8 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Tue, 22 Sep 2026 21:32:57 +0900 Subject: [PATCH 2/3] binary tree level order traversal solution --- binary-tree-level-order-traversal/yuseok89.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 binary-tree-level-order-traversal/yuseok89.py diff --git a/binary-tree-level-order-traversal/yuseok89.py b/binary-tree-level-order-traversal/yuseok89.py new file mode 100644 index 0000000000..e72c4c25c2 --- /dev/null +++ b/binary-tree-level-order-traversal/yuseok89.py @@ -0,0 +1,29 @@ +# TC: O(N) +# SC: O(N) +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + def levelOrder(self, root: TreeNode | None) -> list[list[int]]: + + ret = [] + + def preOrder(root: TreeNode | None, height: int): + if len(ret) == height: + ret.append([]) + + ret[height].append(root.val) + + if root.left: + preOrder(root.left, height + 1) + if root.right: + preOrder(root.right, height + 1) + + if root: + preOrder(root, 0) + + return ret + From 7b5bbbafa2f1213943e540e4f4ce063baf668173 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Tue, 22 Sep 2026 21:34:23 +0900 Subject: [PATCH 3/3] house robber ii solution --- house-robber-ii/yuseok89.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 house-robber-ii/yuseok89.py diff --git a/house-robber-ii/yuseok89.py b/house-robber-ii/yuseok89.py new file mode 100644 index 0000000000..37e4dcfb06 --- /dev/null +++ b/house-robber-ii/yuseok89.py @@ -0,0 +1,19 @@ +# TC: O(N) +# SC: O(1) +class Solution: + def rob(self, nums: list[int]) -> int: + + n = len(nums) + + def calc(nums, s, e): + rob, skip = 0, 0 + for idx in range(s, e): + rob, skip = skip + nums[idx], max(rob, skip) + + return max(rob, skip) + + if n == 1: + return nums[0] + + return max(calc(nums, 0, n - 1), calc(nums, 1, n)) +