Reverse Bits: runtime 4ms


  • 0
    H
    class Solution {
    public:
        uint32_t reverseBits(uint32_t n) {
            uint32_t i,high,low,tmp=0;
    	for(i=0;i<16;i++)
    	{
    		high=(n>>(31-i))&0x1;
    		low=(n>>i)&0x1;
    		//
    		if(low)
    		{
    			tmp=tmp|(1<<(31-i));
    		}
    		//
    		if(high)
    			tmp=tmp|(1<<i);
    	}
    
    	return tmp;
        }
    };

Log in to reply
 

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