Palindrome Number

来源:互联网 发布:csgo游戏优化 编辑:程序博客网 时间:2024/06/05 03:53

和Reverse Integer类似,按位处理,而不要转换成String。

class Solution {public:    bool isPalindrome(int x) {        if(x < 0) return false;        int base = 1;        while(x/base >= 10) base*=10;                while(x && base)        {            int highradix = x/base;            int lowradix = x%10;            if(highradix != lowradix)                return false;            x %= base;            x /= 10;            base /= 100;        }        return true;    }};

0 0