An easy 4ms C++ solution


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

Log in to reply
 

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