Determine whether an integer is a palindrome. Do this without extra space.
MathHave you met this question in a real interview?
Yes
No
思路:就是那样QAQ,很普通的回文判断,WA点:负数不是回文数。
实现代码:
<span style="font-size:12px;">class Solution {
public:
bool isPalindrome(int x) {
if(x<0) return false;
int cnt=0;
int a[100];
memset(a,0,sizeof(a));
while(x)
{
int c=x%10;
a[cnt++]=c;
x/=10;
}
int i,j;
for(i=0,j=cnt-1;i<j;i++,j--)
{
if(a[i]!=a[j]) return false;
}
return true;
}
};</span>
版权声明:本文为博主原创文章,未经博主允许不得转载。