Recently updated blog
- Huawei od 2023 | What is Huawei od, od salary, od machine test questions list
- A complete collection of Huawei OD machine test questions, using Python to solve Huawei machine test questions | Machine Test Collection
- [Huawei OD machine test] full process analysis + experience sharing, question type sharing, cheating prevention guide
- Huawei od machine test, exclusive compilation of practical skills of those who have participated in the machine test
Solution to this article: Replace the binary tree by path
topic description
Replace a sub-binary tree into another root binary tree according to the path to get a new binary tree. The replacement action satisfies the following conditions
- The same node, the sub-binary tree and the root binary tree exist at the same time, then take the value of the sub-binary tree
- For the same node, the sub-binary tree exists, but the root binary tree does not exist, then the value of the sub-binary tree is taken
- For the same node, the child binary tree does not exist, but the root binary tree exists, then take the value of the root binary tree
- After the parent node is processed, recursively process the child nodes until the child binary tree and the root binary tree do not have child nodes and exit