C++ solution 4ms and easy to understand


  • 0
    H

    class Solution {
    public:
    uint32_t reverseBits(uint32_t n) {
    uint32_t m=0;
    for(int i=0;i<32;i++){
    if(n%2==0){
    m=m<<1;
    }else if(n%2==1){
    m=m<<1;
    m++;
    }
    n=n>>1;
    }
    return m;
    }
    };


Log in to reply
 

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