Q190. Reverse Bits
191. Reverse Bits
分析
C++代码
class Solution {
public:
uint32_t reverseBits(uint32_t n) {
uint32_t res = 0;
for(int i = 0; i < 32; i++){
uint32_t bit = n & 1;
n = n >> 1;
res = res << 1;
res += bit;
}
return res;
}
};Last updated