Palindrome Number

Palindrome Number

Total Accepted: 95552 Total Submissions: 318732 Difficulty: Easy

 

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

 

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

 

posted @ 2015-12-18 16:54  zengzy  阅读(127)  评论(0编辑  收藏  举报
levels of contents