9. Palindrome Number (考虑负数的情况)

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

long int reverse(int x) {
    long int ret = 0;
    
    while(x>0){
        ret = ret*10 + x%10;
        x /= 10;
    }
    return ret;
}

bool isPalindrome(int x) {
    if(x<0) return false; //consider case of negative number
    if(x==reverse(x)) return true;
    else return false;
}

 

posted on 2016-04-07 18:22  joannae  阅读(118)  评论(0编辑  收藏  举报

导航