My easy Java solution 2ms may help u


  • 0
    public class Solution {
        // you need treat n as an unsigned value
        public int reverseBits(int n) {
    		int res = 0;
    		for (int i = 0; i < 32; ++i) {
    		    res <<= 1;
    		    if(n != 0){
    			    res += n % 2;
    			    n >>>= 1;
    		    }
    		}
    		return res;
    	}
    }

Log in to reply
 

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