Clean Python Solution


  • 0
    class Solution(object):
        def mergeTrees(self, t1, t2):
            if t1 or t2:
                root = t1 or t2 if not (t1 and t2) else TreeNode(t1.val + t2.val)
                root.left = self.mergeTrees(t1.left if t1 else None, t2.left if t2 else None)
                root.right = self.mergeTrees(t1.right if t1 else None, t2.right if t2 else None)
                return root
            return None

Log in to reply
 

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