My 9ms C++ solution


  • 1
    M
    class Solution {
    public:
        uint32_t reverseBits(uint32_t n) {
            uint32_t p = 0x80000000;
            uint32_t q = 1u;
            while (p > q) {
                if (bool(n & p) ^ bool(n & q)) {
                    n ^= (p | q);
                }
                p >>= 1;
                q <<= 1;
            }
            return n;
        }
    };

Log in to reply
 

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