Leetcode#9 Palindrome Number

原题地址

方法I:

传统的判断回文的方法,左右指针,不断收缩判断

方法II:

将数字翻转,判断翻转后的数字是否相等,溢出也没关系因为溢出以后更加不可能相等了

代码(方法II):

 1 bool isPalindrome(int x) {
 2         int oldx = x;
 3         int newx = 0;
 4         
 5         if (x < 0)
 6             return false;
 7         
 8         while (oldx > 0) {
 9             newx = newx * 10 + oldx % 10;
10             oldx /= 10;
11         }
12         
13         return newx == x;
14 }
原文地址:https://www.cnblogs.com/boring09/p/4267935.html