Palindrome Number 判断整数是否回文

来源:互联网 发布:电子白板软件功能 编辑:程序博客网 时间:2024/06/04 19:00

Palindrome Number

 

Determine whether an integer is a palindrome. Do this without extra space.

class Solution {public:    bool isPalindrome(int x) {        if(x<0)          return false;        if(x==0)          return true;        int k=x,b,left,right;        b=1;        while(k>=10)        {            k/=10;            b*=10;        }                while(x)        {            left=x/b;            right=x%10;            if(left!=right)                return false;            x=x-left*b;            x/=10;            b=b/100;        }        return true;    }};

0 0