This is the code which time exceed. And if I change >> to >>>, the solution is accepted.


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

    }


Log in to reply
 

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