15.42% C Solution


  • 0
    A
    uint32_t reverseBits(uint32_t n) {
        uint32_t rev_n = 0;
        int loops = sizeof(n) * 8;
        int i;
        
        for (i = 0; i < (loops-1); i++) {
            rev_n |= (n & 0x1);
            n >>= 1;
            rev_n <<= 1;
        }
        
        rev_n |= (n & 0x1);
        n >>= 1;
        
        return rev_n;
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.