Skip to content

Commit bb53e35

Browse files
committed
solved reverse-bits
1 parent b87ce6f commit bb53e35

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

reverse-bits/samthekorean.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# TC : O(1)
2+
# SC : O(1)
3+
# Reason : The input is fixed to be 32 bit resulting in time and space complexity being O(1)
4+
class Solution:
5+
def reverseBits(self, n: int) -> int:
6+
binary_string = bin(n)[2:].zfill(32)
7+
reversed_binary_string = binary_string[::-1]
8+
9+
return int(reversed_binary_string, 2)

0 commit comments

Comments
 (0)