Palindrome Number

 

 如图,这次没有当作字符处理,和昨天的问题相似,改用运算解决。但是没有考虑溢出的情况:

class Solution {
    public boolean isPalindrome(int x) {
        if (x<0){
            return false;
        }
        if (x==0){
            return true;
        }
        int oldValue=x;
        int newValue=0;
        while (x>0){
            int last=x%10;
            x=x/10;
            newValue=newValue*10+last;
        }
        return newValue==oldValue;
    }
}

 

posted @ 2020-03-22 00:24  l2c  阅读(99)  评论(0)    收藏  举报