Accepted Cpp version in 61ms


  • -23
    H
    class Solution {
    public:
        bool isPalindrome(int x) {
            if(x<0) return false;
            int y(x);
            int len=0;
            while(y){
                y=y/10;
                len++;
            }
            if(len==1) return true;
            while(len>0){
                int div=pow(10,len-1);
                if(x/div!=x%10) return false;
                if(x) x=x % div;
                if(x) x=x/10;
                len-=2;
            }
            return true;
        }
    };

  • -1
    J
    This post is deleted!

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.