9. 回文数 by 2018-04-22

判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。

class Solution {
public:
    bool isPalindrome(int x) {
        if (x < 0)
            return false;
        int temp = x;
        int res = 0;
        while (x)
        {
            res = res * 10 + x % 10;
            x /= 10;
        }

        return temp == res;
    }
};

你可能感兴趣的:(9. 回文数 by 2018-04-22)