专栏名称: 每日一道算法题
学习算法是一种信仰,每天都需要坚持!
目录
相关文章推荐
算法与数学之美  ·  又一位!著名数学家,在美近40年后,回到中国! ·  2 天前  
算法与数学之美  ·  被数学虐了这么多年,才发现其实是打开方式错了! ·  2 天前  
51好读  ›  专栏  ›  每日一道算法题

617. Merge Two Binary Trees

每日一道算法题  · 公众号  · 算法  · 2017-10-29 21:07

正文


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.


Example 1:

Input:

Tree 1 Tree 2

1 2

/ \ / \

3 2 1 3

/ \ \

5







请到「今天看啥」查看全文