1 Star 0 Fork 0

ZENGWatermelon/LeetCode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
617.合并二叉树.py 783 Bytes
一键复制 编辑 原始数据 按行查看 历史
sunzhaoc 提交于 2020-11-27 13:06 . master
'''
Description:
Version: 1.0
Author: Vicro
Date: 2020-11-27 12:16:56
LastEditTime: 2020-11-27 12:21:01
FilePath: \Leetcode\617.合并二叉树.py
'''
#
# @lc app=leetcode.cn id=617 lang=python3
#
# [617] 合并二叉树
#
# @lc code=start
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def mergeTrees(self, t1: TreeNode, t2: TreeNode) -> TreeNode:
if not t1:
return t2
if not t2:
return t1
meregd = TreeNode(t1.val + t2.val)
meregd.left = self.mergeTrees(t1.left, t2.left)
meregd.right = self.mergeTrees(t1.right, t2.right)
return meregd
# @lc code=end
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/watermelonTT/LeetCode.git
git@gitee.com:watermelonTT/LeetCode.git
watermelonTT
LeetCode
LeetCode
master

搜索帮助