9. Palindrome Number

题目:判断一个数是不是回文数,注意负数不是回文数

思路:求出该数的倒置数,判断是否相等即可。

代码:

class Solution {
    public boolean isPalindrome(int x) {
       if(x<0){
            return false; //负数不是回文数字
        }
        int ax =0;
        int b = x;
        while(b>0){
            ax = ax*10+b%10;
            b/=10;
        }
        if(ax == x){
            return true;
        }else return false;
    }
}

你可能感兴趣的:(9. Palindrome Number)