题目链接
分析
输入一个int数字,判断该数字是否满足回文串的特点。
负数的话一律认为不符合
代码1
我直接用vector自带的“==”来判断,这方法很便捷,但应该不是题目本意。
class Solution {
public:
bool isPalindrome(int x) {
if(x<0){
return false;
}
vector<int> vec1;
while(x!=0){
vec1.push_back(x%10);
x /= 10;
}
if(vec1.size()==1) return true;
vector<int> vec2 = vec1;
reverse(vec2.begin(), vec2.end());
if(vec2==vec1){
return true;
}else{
return false;
}
}
};