solved with python generator


  • 0
    L

    solved with python generator

    class Solution(object):
        def isPalindrome(self, x):
            """
            :type x: int
            :rtype: bool
            """
            s = '0' if x == 0 else ''
    
            if x >= 0:
                target = self.generator_x(x)
                for p in target:
                    p = str(p)
                    s += p
    
            else:
                return False
                
            return True if int(s) == x else False
    
        def generator_x(self, x):
            while x:
                y = x%10
                x = x/10
                yield y
    

Log in to reply
 

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