```
class Solution {
public:
int reverse(int x) {
bool positive = true;
if(x<0){
x=-x;
positive = false;
}
long long int temp=0;
while(x>0){
temp = temp*10+x%10;
x/=10;
}
if((temp>>31)>0)
return 0;
if(positive)
return (int)temp;
return (int)-temp;
}
};
```