9. Palindrome Number(注意swap函数用法)

Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.

class Solution {
public:
    string reverseString(string s) {
        int i=0,j=s.size()-1;
        while(i<j)
        {
            swap(s[i],s[j]);
            i++;
            j--;
        }
        return s;
    }
    bool isPalindrome(int x) {
        string a = to_string (x);
        string b = reverseString (a);
        return(a == b);
    }
};

猜你喜欢

转载自blog.csdn.net/PiscesDAI/article/details/84529736
今日推荐