
Problem Description:
Determine whether an integer is a palindrome. Do this without extra space.
题目大意:
判断一个整数是否是对称数。
Solutions:
首先负数肯定不是对称的。然后可以把数字转化成字符串,存成两个正反序的字符串,如果这两个字符串相等,则是对称的。
Code in C++:
class Solution {
public:
bool isPalindrome(int x) {
if(x<0) return="" false;="" string="" a="" ,b="" ;="" while(x="">0)
{
a+=(char)(x%10+’0’);
b=(char)(x%10+’0’)+b;
x/=10;
}
return a==b;
}
};




近期评论