Leetcode 9回文数

Leetcode 9回文数

class Solution {
public:
    bool isPalindrome(int x) {
        if(x<0)return false;
        if(x/10 == 0) return true;
        bool ans = false;
        
        int const_x =x;
        long y= 0;
        while(x != 0 )
        {
            if(y*10+x%10 > INT_MAX)
                return false;
            y=y*10+x%10;
            x=x/10;
            
        }
        
        
        if(const_x==y)ans=true;
        
        
        
        
        return ans;
    }
};

Leetcode 9回文数
倒序读数看两个是否一致就好了