Python, no conversion to string


  • 0
    W
    def isPalindrome(self, x):
        if abs(x) > 0x7FFFFFFF:
            return False
        elif x < 0:
            return False
    
        exp = 1
        while x / (10 ** exp) != 0:
            exp += 1
        exp -= 1
    
        while exp > 0:
            if x / (10 ** exp) != x % 10:
                return False
            x = x % (10 ** exp)
            x = x / 10
            exp -= 2
        return True

Log in to reply
 

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