Reverse Integer

来源:互联网 发布:手机时间与网络同步 编辑:程序博客网 时间:2024/05/21 08:47
class Solution {
public:
    int reverse(int x)
{
   bool a = true;
   if(x < 0)
   {
       a = false;
       x = -x;
   }
unsigned long int t = 0;
    while(x !=  0)
        {
        t=t*10;
        t=t+x%10;
        x=x-(x%10);
        x=x/10;
}
if(t>2147483647)
   return 0;
else 
{
   int y = t;
   if(!a)
   {
       y = -y;
   }
   return y;
}
    }
};
0 0