Java solution using just bit operations using Integer.MIN_VALUE


  • 0
    J
    public class Solution {
        public int reverseBits(int n) {
            int reverseVal = 0, x = Integer.MIN_VALUE;
            while (x != 0)
            {
            	reverseVal = (reverseVal<<1)  + (n & 1);
            	n >>>= 1;
            	x >>>= 1;
            }
            
            return reverseVal;
        }
    }

Log in to reply
 

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