@chawuciren
2018-11-15T15:14:57.000000Z
字数 493
阅读 663
leetcode
Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.
Example 1:
Input: 121
Output: true
bool isPalindrome(int x) {
int n=reverse(x);
if(n>=0&&n==x)
return true;
else
return false;
}
int reverse(int x) {
if(x>=2147483647||x<=-2147483647){
return 0;
}
int result=0;
int a[10]={0};
int k=0;
int c=0;
int n=x;
while(n!=0){
result=n%10;
a[k]=result;
n/=10;
k+=1;
}
int b=k-1;
result=0;
for(int i=k;i>0;i--){
for(int j=0;j<b;j++){
a[c]*=10;
}
result+=a[c];
c+=1;
b-=1;
}
return result;
}