4-lines concise JAVA, 2ms


  • 0
        public int reverseBits(int n) {
            int res = 0;
            for(int i = 0; i < 31; ++i, n >>>= 1)
                res = ( res + (n & 1) ) << 1;
            return res + (n & 1);
        }
    

Log in to reply
 

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