Find the farthest leaf node of binary tree (example explanation)
•
Java
During the interview, I came across a question: how to find the farthest leaf node of a binary tree and the distance from the leaf node to the root node?
The first reaction must be recursion
How can we find the farthest leaf node and record the distance from the leaf node to the root node? Use a list to keep the path from the root node to the leaf node. The length of the list - 1 is the distance from the leaf node to the root node, and the last node of the list is to the leaf node
I don't need to design binary tree. See my other article for the specific code
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码