3ms C++ solution. 4 Lines.


  • 0
    C

    We are using C++ not C. Why bother to do bit manipulation. Save you some brain power, my friend.

    uint32_t reverseBits(uint32_t n) {
            bitset<32> input(n);
            string s = input.to_string();
            reverse(s.begin(), s.end());
            return bitset<32>(s).to_ulong();
    }

Log in to reply
 

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