9. Palindrome Number

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

 

就是判断 反转后的整数和反转之前的整数是否相等

 

class Solution {  
public:  
    bool isPalindrome(int x) {
        if ((x % 10 == 0) && (x != 0)) return false;
        int tmp = x;
        int y = 0;
        if (x < 0) return false;
        while(tmp > 0) {
            y *= 10;
            y += tmp % 10;
            tmp /= 10;
        }
        return x == y;
    } 
};  

 

posted on 2017-07-17 16:55  Beserious  阅读(93)  评论(0编辑  收藏  举报