HUAWEI OD machine test real test Java implementation [find elements in the tree] [2023 B volume 100 points], with detailed problem-solving ideas

insert image description here

1. Topic description

Knowing all the node information of the tree structure, it is now required to find the content value saved by the node according to the input coordinates (x, y);

in:

x indicates the layer number of the node, the root node is located at layer 0, the child nodes of the root node are located at layer 1, and so on;

y indicates the relative offset of the node in the layer, from left to right, the first node offset is 0, the second node offset is 1, and so on;

2. Enter description

Each node is represented by a one-dimensional array (int[]), all node information forms a two-dimensional array (int[][]), and the 0 position of the two-dimensional array stores the root node;

In the one-dimensional array representing a single node, the 0 position stores the content value, and the subsequent positions store the index position of the child node in the two-dimensional array&

Guess you like

Origin blog.csdn.net/guorui_java/article/details/131622976