1.题目
Determine whether an integer is a palindrome. Do this without extra space.
判断一个整数是否是回文数。
2.思路
此题so easy,负数不是回文数。直接贴代码:
class Solution {
public:
bool isPalindrome(int x) {
if(x < 0) return false;
int tmp = x;
int ans=0;
while(tmp != 0){
ans = ans*10 + tmp%10;
tmp /= 10;
}
return x == ans ?1:0;
}
};
本文介绍了如何不使用额外空间来判断一个整数是否为回文数,详细解释了负数不是回文数的规则,并提供了简洁的代码实现。
250

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



