赞
踩
Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.
给定两个二叉树,并想象当你把其中一个覆盖另一个时,两个树的一些节点是重叠的,而另一个没有。
You need to merge them into a new binary tree. The merge rule is that if two nodes overlap, then sum node values up as the new value of the merged node. Otherwise, the NOT null node will be used as the node of new tree.
您需要将它们合并成一个新的二叉树。合并规则是如果两个节点重叠,则sum节点值作为合并节点的新值。否则,NOT空节点将被用作新树的节点。
Example 1:
Input:
Tree 1 Tree 2
1 2
/ \ / \
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。