LeetCode | Palindrome Number

Palindrome Number

 Total Accepted: 59751 Total Submissions: 200784My Submissions

Determine whether an integer is a palindrome. Do this without extra space.

click to show spoilers.

Show Tags
 Math
Have you met this question in a real interview? 
Yes
 
No

Discuss

思路:就是那样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>

版权声明:本文为博主原创文章,未经博主允许不得转载。

原文地址:https://www.cnblogs.com/Tobyuyu/p/4965322.html