Share my Python solution with implementation of reversing int


  • 0
    L
    class Solution(object):
        # def isPalindrome(self, x):
        #     """
        #     :type x: int
        #     :rtype: bool
        #     """
        #     ### With extra space
        #     if x < 0:
        #         return False
        #     y = int(str(x)[::-1])
        #     if y == x:
        #         return True
        #     return False
        def isPalindrome(self, x):
            """
            :type x: int
            :rtype: bool
            """
            
            if x < 0:
                return False
            y = self.reverseInt(x)
            if y == x:
                return True
            return False
        def reverseInt(self, x):
                answer = 0
                while x != 0:
                    digit = x%10
                    x = x/10
                    answer = answer*10 + digit
                return answer

Log in to reply
 

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