Concise Python version


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

Log in to reply
 

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