您的位置:首页 > 其它

LeetCode | Palindrome Number

2015-06-09 01:42 295 查看


Palindrome Number

Total Accepted: 59751 Total
Submissions: 200784My Submissions

Question
Solution

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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: