Skip to content

Commit 549c2d8

Browse files
committed
reverse-bit complexity
1 parent 1242b3e commit 549c2d8

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

reverse-bits/sungjinwi.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
"""
2+
TC : n의 크기에 상관없이 32번 반복하므로
3+
O(1)
4+
SC : 추가적인 메모리 쓰지 않으므로
5+
O(1)
6+
"""
7+
18
class Solution:
29
def reverseBits(self, n: int) -> int:
310
ret = 0
411
for _ in range(31) :
512
ret |= n & 1
613
ret <<= 1
714
n >>= 1
8-
ret += n & 1
15+
ret |= n & 1
916
return ret

0 commit comments

Comments
 (0)