回文数 题目代码结果 题目 代码 此外还有一种做法类似前面的最大回文字符串(博客有写 刷题第05),把整数tostring再套用前面的来判断就行了。 class Solution { public boolean isPalindrome(int x) { if(x<0)return false; int temp = 0; int y = x; while(x!=0){ temp = temp*10+x%10; //反向输出的标准写法,temp为依次输出最后一位数,x为输出除了最后一位数的前几位数 x = x/10; }return temp==y; } } 结果