如果是负数那肯定不是回文数 反转数字一般都是那两行代码
class Solution {
public:
bool isPalindrome(int x) {
if (x 0) return false;
int xx x;
long ans 0;
while(x){
ans ans*10 x%10;
x x/10;
if(ans xx) return true;
else return false;
Python
class Solution: def isPalindrome(self, x: int) - bool: if x 0: return False return str(x) str(x)[::-1] #看做字符串然后反转



