Maybe best solution so far.


  • 0
    X
    public int reverseBits(int n) {
    		long res = 0;
    		for (int i = 0; i < 32 && n != 0; i++) {
    			if ((n & 1) == 1)
    				res += Math.abs(1 << (32 - i - 1));
    			n >>>= 1;
    		}
    		return (int) res;
    	}
    

Log in to reply
 

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