int reverse(int x) {

```
int t;
long rtn = 0;
int flag = 0;
```

/* int a = n;

int count = 0 ;//记录末尾0出现的次数

while(a % 10 == 0)

{

count++;

a /= 10;

}

*/

if(x == 0)

return 0;

if(x < 0)

{

flag = 1;

x = ~x + 1;

}

while(x)

{

t = x % 10;

rtn = 10 * rtn + t;

x /= 10;

}

if ( rtn > 0x7FFFFFFF || rtn < (-0x7FFFFFFF - 1) ) {

return 0;

}

if(flag)

{

return -rtn;

}

return rtn;

}