当前位置:   article > 正文

617.Merge Two Binary Trees(合并两棵树)_暗物质晕binary合并树

暗物质晕binary合并树

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                             
         / \                       / \                            
        
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/224380
推荐阅读
相关标签
  

闽ICP备14008679号