【LeetCode】9. Palindrome Number

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

class Solution {
public:
    bool isPalindrome(int x) {
        vector<int> v;
        if(x==0) return true;
        if(x<0)  return false;
        while(x>0)
        {
            v.push_back(x%10);
            x= x/10;
        }
        for(int i=0, j = v.size()-1; i < j; i++,j--)
        {
            if(v[i]!=v[j])
             return false;
        }
        return true;
    }
};


你可能感兴趣的:(【LeetCode】9. Palindrome Number)