My solution reversing the integer


  • 0
    V
    class Solution {
    public:
        bool isPalindrome(int x) {
            if (x < 0 )
                return false;
            
            int result = x;
            unsigned long temp = 0;
        
            for( ; x; x /= 10 )
            {
                temp = 10 * temp + x % 10;
                if( temp > INT_MAX )
                    return false;
            }
            return temp == result;
        }
    };

Log in to reply
 

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