A tree is an undirected graph in which any two vertices are connected by exactly one path. Given a tree of n nodes labelled from 0 to n - 1, and an array of n - 1 edges, you can choose any node of the tree as the root. The height of a rooted tree is the number of edges on the longest downward path between the root and a leaf. Return a list of all MHTs root labels. You can return the answer in any order.
Java
Minimum Height Trees
A tree is an undirected graph in which any two vertices are connected by exactly one path. Given a tree of n nodes labelled from 0 to n - 1, and an array of n - 1 edges, you can choose any node of the tree as the root. The height of a rooted tree is the number of edges on the longest downward path between the root and a leaf. Return a list of all MHTs root labels. You can return the answer in any order.