A c++ solution that beats 100%,don't need to handle the overflow.


  • 0
    A

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


Log in to reply
 

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