递归合并二叉树 easy
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
func mergeTrees(root1 *TreeNode, root2 *TreeNode) *TreeNode {
if root1 != nil && root2 != nil {
root1.Left = mergeTrees(root1.Left, root2.Left)
root1.Right = mergeTrees(root1.Right, root2.Right)
root1.Val = root1.Val + root2.Val
} else if root2 != nil {
root1 = root2
}
return root1
}
标签:TreeNode,Val,617,二叉树,Left,root1,leetcode,root2
From: https://www.cnblogs.com/wudanyang/p/17020485.html