Python solution


  • 0
    A
        def mergeTrees(self, t1, t2):
            """
            :type t1: TreeNode
            :type t2: TreeNode
            :rtype: TreeNode
            """
            
            if t1 is None and t2 is None:
                return None
            
            if t1 is None:
                return t2
            
            if t2 is None:
                return t1
            
            t1.val += t2.val
            
            t1.left = self.mergeTrees(t1.left, t2.left)
            t1.right = self.mergeTrees(t1.right, t2.right)
            
            return t1
    

Log in to reply
 

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