4ms C++ solution


  • 0
    D
    class Solution {
    public:
        uint32_t reverseBits(uint32_t n) {
            if(n == 0)
                return 0;
            
            long int rst = 0;
            
            long int temp;
            int step = 0;
            
            while(step <= 31)
            {
                temp = n & 1;
                n = n >> 1;
                if(temp != 0)
                    rst += (temp<<(31 - step));
                step++;
            }
            
            return rst;
            
        }
    };

Log in to reply
 

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