C++ Easy to understand approach!


#1

int Solution::reverse(int A) {
try{
int i=0;
string ans="";
string As = to_string(A);
if(As[0]==’-’){
i=1;
}
for(int x=As.size()-1;x>=i;x–){
ans+=As[x];
}
if(i==1){
return -1*stoi(ans);
}
return stoi(ans);
}
catch(…){
return 0;
}
}