161. Minimum Height Trees

Given a tree with n vertices and an array of edges edges. Return all roots for which the tree height is minimal (leaf-removal method).
Example 1
Input: n = 4, edges = [[1,0],[1,2],[1,3]]
Output: [1]
Explanation: Star center is the only MHT root.
Example 2
Input: n = 6, edges = [[3,0],[3,1],[3,2],[3,4],[5,4]]
Output: [3,4]
Explanation: Two possible minimum-height roots.
graph
JavaScript
Loading...
Line 1, Char 1