C++ solution, beats 100%, just 8 lines!


  • 0
    R
    bool isPalindrome(int x) {
            
            if(x<0)return false;
            int tmp = x, reverse = 0;
            while(tmp)
            {
                reverse = reverse*10+tmp%10;
                tmp /= 10;
            }
            
            return x==reverse;
            
        }
    

Log in to reply
 

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