From : https://leetcode.com/problems/palindrome-number/
Determine whether an integer is a palindrome. Do this without extra space.
class Solution {
public:
bool isPalindrome(int x) {
if(x<0) return false;
unsigned int t=x, low=1, high=1;
while(t/10) { high *= 10; t /= 10; }
while(low < high) {
if(x/high%10 != x/low%10) return false;
low *= 10;
high /= 10;
}
return true;
}
};
本文提供了一种不使用额外空间的方法来判断整数是否为回文数,通过反转一半的数字并与原始数字进行比较实现。
670

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



