C++ 10 ms solution using std::bitset and std::string

  • 0

    Here is the code:

    uint32_t reverseBits(uint32_t n) {
        const size_t BIT_SIZE = 32;
        bitset<BIT_SIZE> bs(n);
        string str1 = bs.to_string();
        string str2;
        for (auto it = str1.rbegin(); it != str1.rend(); ++it) {
            str2 += *it;
        return bitset<BIT_SIZE>(str2).to_ulong();

Log in to reply

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