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

 

相关文章:

  • 2021-12-11
  • 2022-12-23
  • 2022-12-23
  • 2021-10-05
猜你喜欢
  • 2021-07-03
  • 2021-12-29
  • 2022-12-23
  • 2022-12-23
  • 2021-08-31
  • 2021-12-08
相关资源
相似解决方案