My LeetCode grinding. Trying to do a problem a day.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

problem.txt 919B

123456789101112131415161718192021222324
  1. 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.
  2. 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.
  3. Example 1:
  4. Input:
  5. Tree 1 Tree 2
  6. 1 2
  7. / \ / \
  8. 3 2 1 3
  9. / \ \
  10. 5 4 7
  11. Output:
  12. Merged tree:
  13. 3
  14. / \
  15. 4 5
  16. / \ \
  17. 5 4 7
  18. Note: The merging process must start from the root nodes of both trees.