题目:9. 回文数
是以前上课的基础题(要是世界上所有东西都是自己知道解法的题就好了)
解答:
class Solution {
public:
bool isPalindrome(int x) {
if(x<0)
return false;
int t=x;
long long int res=0;
while(t>0){
int a=t%10;
t=t/10;
res=res*10+a;
}
if(res==x)
return true;
return false;
}
};
注意res如果是int会溢出。