Share my 4ms C++ answer


  • 0
    F
    class Solution {
    public:
        uint32_t reverseBits(uint32_t n) {
            int k,l,m;
            k = (n&0xAAAAAAAA)>>1;
            l = (n&0x55555555)<<1;
            m = k|l;
            
            k = (m&0xCCCCCCCC)>>2;
            l = (m&0x33333333)<<2;
            m = k|l;
            
            k = (m&0xF0F0F0F0)>>4;
            l = (m&0x0F0F0F0F)<<4;
            m = k|l;
            
            k = (m&0xFF00FF00)>>8;
            l = (m&0x00FF00FF)<<8;
            m = k|l;
            
            k = (m&0xFFFF0000)>>16;
            l = (m&0x0000FFFF)<<16;
            m = k|l;
            
            return m;
        }
    };

Log in to reply
 

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