Python code, concise but a little slow.


  • 0
    H
    class Solution(object):
        def isPalindrome(self, x):
            """
            :type x: int
            :rtype: bool
            """
            if x < 0:
                return False
            
            magic = 1
            
            n = x / 10
            while n > 0:
                n = n / 10
                magic = magic * 10
            
            while magic > 0:
                digit = x % 10
                x = (x - digit * magic) // 10
                magic = magic / 100
                
            return x == 0

Log in to reply
 

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