题目描述:
我的解题:
1.用第七题的方法,将数翻转后与原数比较
class Solution {
public:
bool isPalindrome(int x) {
if(x>=0&&x<=9)
return true;
if(x<0||x%10==0)
return false;
int temp=x;
long a=0;
while(temp!=0){
a=a*10+temp%10;
temp/=10;
}
return x==a?true:false;
}
};
2. 转为字符串操
reverse()函数将左闭右开区间内的元素全部逆序
class Solution {
public:
bool isPalindrome(int x) {
string a=to_string(x);
string b=a;
reverse(b.begin(),b.end());
return a==b?true:false;
}
};