2ms java solution


  • -2
    T

    public class Solution {
    // you need treat n as an unsigned value
    public int reverseBits(int n) {

        int j=0,result=0;
        for(int i=0;i<32; i++) {
        if((n&1)==1) j += 1;
        result=j;
        j <<= 1;//31 times
        n >>= 1;//right one bit
        }
        return result;
    }
    

    }


Log in to reply
 

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