my python code without converting int to str


  • 1
    H
    class Solution(object):
        def isPalindrome(self, x):
            """
            :type x: int
            :rtype: bool
            """
            if x < 0:
                return False
            elif x < 10:
                return True
            mylist = []
            while x != 0:
                mylist.append(x % 10) # add the remainder to the list
                x = x // 10 # reduce the digits of the given number by integer division
            if mylist == mylist[::-1]:
                return True
            else:
                return False
    

    beats 66.70% of submissions


Log in to reply
 

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