A simple solution for JAVA


  • 0
    O

    public class Solution {
    // you need treat n as an unsigned value
    public int reverseBits(int n) {
    int result = 0;
    if(n == 0) return 0;

        for(int i=0;i<32;i++)
        {
            result |= n>>>i<<31>>>i;
        }
        return result;
    }
    

    }


Log in to reply
 

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