码迷,mamicode.com
首页 > 其他好文 > 详细

Leetcode 617. Merge Two Binary Trees

时间:2019-03-23 18:39:18      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:bin   UNC   bsp   port   cache   binary   obj   pre   class   

import functools
class Solution(object):
    @functools.lru_cache()
    def mergeTrees(self, t1, t2):
        if t1 and t2:
            root = TreeNode(t1.val + t2.val)
            root.left = self.mergeTrees(t1.left, t2.left)
            root.right = self.mergeTrees(t1.right, t2.right)
            return root
        else:
            return t1 or t2

 

Leetcode 617. Merge Two Binary Trees

标签:bin   UNC   bsp   port   cache   binary   obj   pre   class   

原文地址:https://www.cnblogs.com/zywscq/p/10585011.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!