C++ solution 4ms . Easy to understand


  • 0
    T

    class Solution {
    public:
    uint32_t reverseBits(uint32_t n) {
    uint32_t mask=1,sum=0,i=0;
    while (i<32){
    if ((n&mask)==0){
    sum=sum<<1;
    }
    else {
    sum=sum<<1;
    sum|=1;
    }
    mask<<=1;
    i++;
    }
    return sum;
    }
    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.