[LeetCode] 190. Reverse Bits

원숭2·2022년 1월 28일
0

LeetCode

목록 보기
18/51

문제

풀이

  1. 입력인 32비트를 유지를 위해 이진수를 뒤집는 과정고 0을 padding 해줘야 함.

코드

class Solution:
    def reverseBits(self, n: int) -> int:
        binary = bin(n)[2:][::-1]
        
        res = binary + '0' * (32 - len(binary))
        
        return int(res, 2)

0개의 댓글