yeonghwanjeon / coding_practice

0 stars 0 forks source link

[LeetCode]merge two binary trees (완료) #11

Open yeonghwanjeon opened 5 years ago

yeonghwanjeon commented 5 years ago

class Solution(object): def mergeTrees(self, t1, t2): """ :type t1: TreeNode :type t2: TreeNode :rtype: TreeNode """ if t1 == None : return t2

    if t2 == None :
        return t1

    t = TreeNode(t1.val + t2.val)
    t.left = self.mergeTrees(t1.left, t2.left)
    t.right = self.mergeTrees(t1.right, t2.right)

    return t
yeonghwanjeon commented 5 years ago