public class Solution {
// you need treat n as an unsigned value
public int reverseBits(int n) {
int result = 0;
for (int i = 0; i < 32; i++) {
result <<= 1;
if ((n & 1) == 1) {
result ^= 1;
}
n >>= 1;
}
return result;
}
}
190. 颠倒二进制位
最新推荐文章于 2024-09-08 12:41:07 发布