LeetCode OJ 9 Palindrome Number

来源:互联网 发布:用友软件操作 编辑:程序博客网 时间:2024/06/11 09:39

题目:

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

难度

easy

思路:每一个提取最高位和最低位进行比较即可

代码如下

using namespace std;class Solution {public:    bool isPalindrome(int x) {        if(x<0)            return false;        if(x<10)            return true;        int d=1;//divisor        while(x/d>=10)            d*=10;//calculate the quantitatively of x        while(x>0){            int r=x%10;            int l=x/d;            if(r!=l)                return false;            x=x%d/10;            d/=100;        }        return true;    }};


0 0