```
class Solution {
public:
int reverse(int x) {
int y = x % 10;
int z = x, w;
x /= 10;
while (x != 0)
{
w = y;
y *= 10;
// check *
if (y/10 != w)
return 0;
y += x % 10;
x /= 10;
}
// check +
int sign = (y >> 31) & 0x1;
if (( z>0 && sign == 1) || ( z<0 && sign == 0))
return 0;
return y;
}
};
```