-->
当前位置:首页 > 题库

PROGRAMMING:The last node of level K of binary tree

Luz5年前 (2021-05-10)题库513
Given a non empty binary tree, the data field of its node is an integer that is not equal to 0. Please write a program to output the value of the last node of the k-th layer in the binary tree. If it does not exist, output 0.
###Input format:
Enter a group of integers separated by spaces in line 1, the number of which is no more than 100, indicating the first root sequence of binary tree with null pointer information. The null pointer information is represented by 0. The second line is an integer K.
###Output format:
The output is an integer, which represents the value of the last node of the k-th layer in the binary tree. If it does not exist, the output is 0.
###Input sample 1:
```in
1 2 0 0 3 0 0
one
```
###Output sample 1:
```out
three
```
###Input sample 2:
```in
1 -2 0 0 3 -1 0 0 -1 0 0
two
```
###Output sample 2:
```out
-1
```







answer:If there is no answer, please comment