slow but pythonic: yield iterator and functional


  • 0
    X
    class Solution(object):
        def it(self, root):
            if not root:
                raise StopIteration
            for val in self.it(root.left):
                yield val
            yield root.val
            for val in self.it(root.right):
                yield val
            
        def getMinimumDifference(self, root):
            lst = list(self.it(root))
            return min(map(lambda p:abs(p[0] - p[1]), zip(lst, lst[1:])))
            
    

Log in to reply
 

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