9.jpg

    代码 :

    1. class Solution {
    2. public:
    3. bool isPalindrome(int x) {
    4. if(x < 0) return false;
    5. long long res = 0;
    6. int tmp = x;
    7. while(x) {
    8. res = res * 10 + x % 10;
    9. x /= 10;
    10. }
    11. return tmp == res;
    12. }
    13. };
    1. class Solution {
    2. public:
    3. bool isPalindrome(int x) {
    4. string res = to_string(x);
    5. auto s = res;
    6. reverse(res.begin(), res.end());
    7. return res == s;
    8. }
    9. };