LeetCode | Palindrome Number

来源:互联网 发布:开淘宝网店的条件 编辑:程序博客网 时间:2024/05/29 14:29

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>

0 0
原创粉丝点击