回文数

Posted on 2018-09-05 20:04  otonashi  阅读(120)  评论(0)    收藏  举报

判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。

class Solution {
    public boolean isPalindrome(int x) {
        int res=0;
        int rev=x;
        while(x!=0){
            int a=x%10;
            x/=10;
            res=res*10+a;
        }
        if(res==rev&&rev>=0){
            return true;
        }
        else{
            return false;
        }
    }
}