Determine whether an integer is a palindrome. Do this without extra space.
class Solution {
public:
bool isPalindrome(int x) {
if(x < 0) return false;
string a = "";
while(x)
{
a += x % 10 + '0';
x /= 10;
}
string b(a);
reverse(a.begin(), a.end());
return a == b;
}
};

本文介绍了一种不使用额外空间来判断整数是否为回文数的方法,通过将整数转换为字符串并进行反转比较实现。

被折叠的 条评论
为什么被折叠?



