Solution in java O(1)


  • -1
    R
    public int reverseBits(int n) {        
            long result = 0;
            String r = "";
        	int count = 1;
            while(count<=32){
            	int lsbit = n&1;
            	r += lsbit;
            	n = n>>1;
            	count++;
            }
            
            result= Long.parseLong(r, 2);
            
            return (int)result;
        }

Log in to reply
 

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