Friday, September 15, 2017

190. Reverse Bits

https://leetcode.com/problems/reverse-bits/description/
    uint32_t reverseBits(uint32_t n) {
        int res = 0, f = 1;
        for(int i=0; i<32; i++, n >>= 1) {
            res <<= 1;
            res |= (n & 1);
        }
        return res;
    }

No comments:

Post a Comment