uint32_t reverseBits(uint32_t n)
uint32_t r = 0;
for (int i = 0; i < 32; ++i)
r = r << 1;
r = ((n >> i) & 1) ? (r | 1) : r;
Here is my inside off the loop:
if( n & (1 << (32-1-i)) )
r |= (1 << i);
I got 8ms for it, also with c++.
abandon r = r << 1; good idea
r = (n&(1<<(31-i)))?(r|(1<<i)):r;
do the same thing
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.