[容易] 合并二叉树

[容易] 合并二叉树

[题]

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.

[解]

Method1
复杂的方法,遇到了值传递和引用传递的问题,在方法中重新声明对象不会改动真正的对象,而是会重新为方法内对象声明地址,见这里

Method2
没有构造新方法,在原方法中进行了merging

Method3
将merge的结果直接保存在其中一个树上