C++ working code


#1

unsigned int Solution::reverse(unsigned int A) {

vector<int> v(32,0);
unsigned int B = A;

int i=31;
while(B){
    int r=B%2;
    if(r>0) v[i]=1;
    i--;
    B>>=1;
}

unsigned int ans=0;
for(int i=0;i<32;++i){
    if(v[i]==1) ans+=pow(2,i);
}

return ans;

}