Dead simple python code


  • 0
    class Solution(object):
        def search(self, root, array, leftFirst):
            array.append(root.val if root else root)
    
            if root:
                [self.search(child, array, leftFirst) for child in ((
                 root.left, root.right) if leftFirst else (root.right, root.left))]
    
        def isSymmetric(self, root):
            l1, l2 = [], []
            [self.search(root, *args) for args in ((l1, True), (l2, False))]
            return l1 == l2

Log in to reply
 

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