We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4c8b68f commit 566f0f9Copy full SHA for 566f0f9
reverse-bits/jinah92.py
@@ -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
@@ -0,0 +1,12 @@
+# O(n) time, O(n) space
+ 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 commit comments