A Recursive Python Solution


  • 0
    S
    class Solution:
        def isPalindrome(self, x):
            if x < 0 : return False
            return self.reverseNum(x) == x
    
        def reverseNum(self, n, partial=0):
            if n == 0:
                return partial
            return self.reverseNum(n / 10, partial * 10 + n % 10)

Log in to reply
 

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