Java simple solution


  • 0
    W
    public class Solution {
    // you need treat n as an unsigned value
    public int reverseBits(int n) {
        long result = 0L;
        int i=0;
        for(;n!=0&&i<32;i++,n>>=1){
            result<<=1;
            result|=(n&1);
        }
        return (int)result<<(32-i);
    }
    

    }


Log in to reply
 

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