Skip to content

Commit e54ac6a

Browse files
committed
reverse-bits solution
1 parent cbeb594 commit e54ac6a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

reverse-bits/yyyyyyyyyKim.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
def reverseBits(self, n: int) -> int:
3+
4+
answer = 0
5+
6+
for i in range(32):
7+
answer <<= 1 # 왼쪽으로 한 칸 밀어서 자리 확보
8+
answer |= (n&1) # n의 마지막 비트 추출해서 answer 맨 뒤에 추가
9+
n >>= 1 # n 오른쪽으로 한 칸 밀기
10+
11+
return answer

0 commit comments

Comments
 (0)