Palindrome Number

2017-12-20  本文已影响0人  无云清晨

判断整数是否是回文

bool isPalindrome(int x) {
     
   if(x <  0)
   {
      return false;
   }
   int t = x / 10;
   int length= 1;
   while(t)
   {
     length = length * 10;
      t = t / 10;
   }

   int left;
   int right;
   int r = x;
   while(x)
   {
     left = r / length;
     right = x % 10;
     if(left != right)
     {
        return false;
     }

     r = r  %  length;
     length = length / 10;

     x = x/10;
   }

   return true;
    }

上一篇下一篇

猜你喜欢

热点阅读