day2-<回文数>


题目描述:

#include 
using namespace std;


class Solution {
public:
    bool isPalindrome(long long x) {
        long long temp = x, reX = 0;

        if(x < 0 || (x != 0 && x %10 == 0))
        {
            return false;
        }
        if(x == 0)
        {
            return true;
        }

        while(temp != 0)
        {
            reX = reX * 10 + temp % 10;
            temp /= 10;
        }
        return reX == x ? true : false;
    }
};


int main()
{
    Solution S;
    int x;
    cin >> x;

    if(S.isPalindrome(x))
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    return 0;
}

心得:

没有什么技术难点,就是需要讲所有情况都考虑周全,比如说小于等于0,个位数的情况,都要涉猎其中。

相关