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);
    }
};

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

相关文章:

  • 2021-08-16
  • 2021-04-11
  • 2021-12-12
  • 2021-09-22
  • 2021-04-02
猜你喜欢
  • 2022-01-23
  • 2021-12-03
相关资源
相似解决方案