9. Palindrome Number

来源:互联网 发布:杭州比较好的美工培训 编辑:程序博客网 时间:2024/06/05 14:35

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


          

class Solution {public:    bool isPalindrome(int x) {        if(x < 0)        return false;        int y = 0;        int X = x;        while(X){            y = y*10 + X%10;            X /= 10;        }        if (x==y)        return true;        else         return false;            }};


                                                 Brilliant solution!

class Solution {public:    bool isPalindrome(int x) {        if(x<0|| (x!=0 &&x%10==0)) return false;        int sum=0;        while(x>sum)        {            sum = sum*10+x%10;            x = x/10;        }        return (x==sum)||(x==sum/10);    }};



0 0
原创粉丝点击