Palindrome Number

注意负数

-2147483648的绝对值还是自己!!!(overflow)

 1 public class Solution {
 2     public boolean isPalindrome(int x) {
 3         // IMPORTANT: Please reset any member data you declared, as
 4         // the same Solution instance will be reused for each test case.
 5         if( x<0 )
 6             return false;
 7         int tmp = x;
 8         int mask = 1;
 9         tmp /= 10;
10         while(tmp > 0)
11         {
12             mask *= 10;
13             tmp /= 10;
14         }
15         
16         while(x > 0)
17         {
18             if(x / mask == x % 10)
19             {
20                 x %= mask;
21                 x /= 10;
22                 mask /= 100;
23             }
24             else
25                 return false;
26         }
27         return true;
28         
29     }
30 }

 

原文地址:https://www.cnblogs.com/jasonC/p/3407854.html