8/23/2020

[LeetCode] 190. Reverse Bits

 Problem : https://leetcode.com/problems/reverse-bits/



class Solution:
    def reverseBits(self, n: int) -> int:
        result = 0
        
        for i in range(32):
            result = result << 1
            result = result | ((n >> i) & 1)
           
        return result

No comments:

Post a Comment