Determine whether an integer is a palindrome. Do this without extra space.

这题貌似解法挺多,直接用简单的把数倒置,没有考虑数据溢出的问题,如需解决可以把转置数设为long long即可。另外方法可以用到前后匹配、递归比较等。

 1 class Solution {
 2 public:
 3     bool isPalindrome(int x) {
 4         int a=x;
 5         int n=0;
 6         if(x<0)
 7           return false;
 8         while(x)
 9         {
10             n*=10;
11             n+=x%10;
12             x/=10;
13         }
14         if(n==a)
15         return true;
16         else return false;
17     }
18 };