Huawei OD machine test candidates [recall questions], path replacement binary tree, Python answer

Recently updated blog

insert image description here

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

  1. 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
  2. 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
  3. 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
  4. 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

Guess you like

Origin blog.csdn.net/hihell/article/details/130141493