My solution with c++(9ms)


  • 0
    B
    class Solution {
    public:
        uint32_t reverseBits(uint32_t n) {
            uint32_t sum = 0;
            uint32_t i = 31;
            while ( n ) {
                if ( n & 1 == 1 ) {
                    sum += ( 1 << i );
                }
                i--;
                n >>= 1;
            }
            return sum;
        }
    };

Log in to reply
 

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