```
class Solution {
public:
int reverse(int x) {
if(x == 0) return x;
long t,answer=0;
vector<long> l;
while(x)
{
t = x%10;
l.push_back(t);
x /= 10;
}
vector<long>::iterator it;
for(it = l.begin(); it<=l.end()-1; it++){
answer = *it + answer*10;
}
if(answer > (long)pow(2,31) || answer < -(long)pow(2,31)) return 0;
return answer;
}
};
```