c++
class Solution {
public:
int reverse(int x) {
long long int ans=0;
int tag=0;
while(x)
{
long long int y =x%10;
x/=10;
if(y==0&&tag==0)
continue;
else{
ans=ans*10+y;
tag=1;
}
}
long long int z = (long long int) pow(2,31)-1;
long long int y = z*-1;
if(ans > z || ans < y)
{
ans=0;
}
return ans;
}
};