leetcode---Palindrome Number

来源:互联网 发布:linux oracle-01081 编辑:程序博客网 时间:2024/05/22 00:43

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

class Solution {public:    bool isPalindrome(int x) {        if(x < 0)  //负数            return false;        int n = x;        int len = 0;        while(n)        {            len++;            n /= 10;        }        if(x >= 0 && len==1) //只有一位数字,且>=0            return true;        int i = 0;        int j = len-1;        while(i < j)        {            if( ( (x/(int)pow(10, j)) % 10 )  != ( (x/(int)pow(10, i)) % 10 ) )                return false;            i++;            j--;        }        return true;    }};
0 0
原创粉丝点击