My simple c++ solution (8 ms)


  • 1
    Y
    class Solution {
    public:
        uint32_t reverseBits(uint32_t n) {
            for(int i=0; i<16; ++i) {
                if (((n >> i) & 1) ^ ((n >> 31-i) & 1))
                    n ^= (1 << i) ^ (1 << 31-i);
            }
            return n;
        }
    };

  • 0
    Y

    This is a very good solution. Thanks.


Log in to reply
 

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