my c++ solution


  • 0
    F
     uint32_t reverseBits(uint32_t n) {  
         for(int i = 0; i < 16; ++i) {
            uint32_t a = 1 << (31-i);
            uint32_t b = 1 << i;
    
            if(!(n & a) != !(n & b)) {
                if(n & a) {  
                    n &= ~a;
                    n |= b;
                } else {
                    n &= ~b;
                    n |= a;
                }  
            }
        }
        return n;
    }

Log in to reply
 

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