Skip to content

Latest commit

 

History

History
29 lines (25 loc) · 644 Bytes

617.md

File metadata and controls

29 lines (25 loc) · 644 Bytes
class Solution:
    def mergeTrees(self, t1, t2):
        """
        :type t1: TreeNode
        :type t2: TreeNode
        :rtype: TreeNode
        """
        t3 = checkNode(self, t1, t2)
        return t3
        
def checkNode(self, t1, t2):
    if t1 == None and t2 == None :
        return None
    elif t1 == None and t2 != None :
        return t2
    elif t1 != None and t2 == None :
        return t1
    else:
        t3 = TreeNode(t1.val+t2.val)
        t3.left = checkNode(self, t1.left, t2.left)
        t3.right = checkNode(self, t1.right, t2.right)        
        return t3

二叉树 遍历 递归

binary trees merge