网站建设资讯

NEWS

网站建设资讯

PalindromeNumber

class Solution {
public:
    bool isPalindrome(int x) {
        int x1=x;
        int x2=x;
        int count=0;
        int num=0;
        int sum=0;
        while(x1>0)//得到未知整数的位数
        {
            x1=x1/10;
            count++;
        }
        for(int i=0;i<=count;i++)
        {
            sum=sum*10+num;//逆置原整数
            num=x2%10;//除10取余数;
            x2=x2/10;
        }
        if(sum==x)
        return true;
        else
        return false;
    }
};

本文标题:PalindromeNumber
本文链接:http://cdweb.net/article/poiose.html