9. Palindrome Number
题目:
解答:
数字化为数字数组,然后验证首尾是否相同即可
class Solution {
public:
bool isPalindrome(int x) {
if(x < 0) return false;
vector<int> vec(32,0);
int index = 0;
while(x > 0){
vec[index++] = x % 10;
x /= 10;
}
for(int i = 0;i < index / 2; ++i){
if(vec[i] != vec[index-1-i])
return false;
}
return true;
}
};
更新会同步在我的网站更新(https://zergzerg.cn/notes/webnotes/leetcode/index.html)