Leetcode 617. Merge Two Binary Trees

Posted 周洋的Blog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode 617. Merge Two Binary Trees相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

[LeetCode] 617. Merge Two Binary Trees

LeetCode(617) Merge Two Binary Trees

Leetcode_easy617. Merge Two Binary Trees

leetcode No617. Merge Two Binary Trees

leetcode No617. Merge Two Binary Trees

[LeetCode&Python] Problem 617. Merge Two Binary Trees