3ms c++ code


  • 0
    W
    class Solution {
    public:
        uint32_t reverseBits(uint32_t n) {
            unsigned int ret=0;
            for(int i=0;i<16;++i){
                unsigned int temp1 = 1<<i;
                unsigned int temp2 = 1<<(31-i);
                if((temp1&n)&&!(temp2&n))
                    ret += temp2;
                else if(!(temp1&n)&&(temp2&n))
                    ret += temp1;
    			else if((temp1&n)&&(temp2&n))
    				ret += (temp1+temp2);
            }
            return ret;
        }
    };
    

Log in to reply
 

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