class Solution {
public:
bool isPalindrome(int x) {
int newX=0,lastX=0;
if(x<0 || ((x%10==0)&&(x!=0))) return false;
//if(x<0 || x%10==0) return false;
//这样的话,如果x是0的话,会输出false
// else if(x==0) return true;/
while(newX<x){
lastX=x;
newX=newX*10+x%10;
x=x/10;
}
// if(lastX==newX) return true;
// else return false;
//错因见图片
return x==newX || x==newX/10;
}
};
[leetcode]回文数-9
最新推荐文章于 2024-06-22 21:53:36 发布