leetcode-190-easy

Reverse Bits

思路一: 遍历 32 位 bit,记录 bit 结果

public int reverseBits(int n) {
    int result = 0;

    int x = 32;
    while (x-- > 0) {
        int bit = n & 1;

        result <<= 1;
        if (bit == 1) {
            result++;
        }

        n >>>= 1;
    }

    return result;
}
posted @ 2022-10-22 20:54  iyiluo  阅读(23)  评论(0)    收藏  举报