Skip to content

Commit 566f0f9

Browse files
committed
feat: week3 easy 문제 풀이
1 parent 4c8b68f commit 566f0f9

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

reverse-bits/jinah92.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# O(1) time, O(1) space
2+
class Solution:
3+
def reverseBits(self, n: int) -> int:
4+
stack = []
5+
while len(stack) < 32:
6+
stack.append(n % 2)
7+
n //=2
8+
9+
result, scale = 0, 1
10+
while stack:
11+
result += stack.pop() * scale
12+
scale *= 2
13+
14+
return result

two-sum/jinah92.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# O(n) time, O(n) space
2+
3+
class Solution:
4+
def twoSum(self, nums: List[int], target: int) -> List[int]:
5+
num_set = {}
6+
7+
for idx, num in enumerate(nums):
8+
other_num = target - num
9+
if other_num in num_set:
10+
return [idx, num_set[other_num]]
11+
else:
12+
num_set[num] = idx

0 commit comments

Comments
 (0)