Skip to content

Commit

Permalink
feat: week3 easy 문제 풀이
Browse files Browse the repository at this point in the history
  • Loading branch information
jinah92 committed Dec 27, 2024
1 parent 4c8b68f commit 566f0f9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions reverse-bits/jinah92.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# O(1) time, O(1) space
class Solution:
def reverseBits(self, n: int) -> int:
stack = []
while len(stack) < 32:
stack.append(n % 2)
n //=2

result, scale = 0, 1
while stack:
result += stack.pop() * scale
scale *= 2

return result
12 changes: 12 additions & 0 deletions two-sum/jinah92.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# O(n) time, O(n) space

class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
num_set = {}

for idx, num in enumerate(nums):
other_num = target - num
if other_num in num_set:
return [idx, num_set[other_num]]
else:
num_set[num] = idx

0 comments on commit 566f0f9

Please sign in to comment.