```
class Solution {
public:
long long int reverse(long long int x) {
long long int q = x, r = 0, sum = 0, flag = 0;
if(q < 9 && q>= 0)
return q;
else {
if(q<0){
flag = 1;
q = -q;
}
while(q > 9){
r = q % 10;
q = q/10;
sum = sum*10 + r;
}
sum = sum*10 + q;
if(flag == 1)
return -sum;
else
return sum;
}
}
};
```