Skip to content

Commit c6996ed

Browse files
refactor 310
1 parent ca9bfa1 commit c6996ed

File tree

1 file changed

+0
-46
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+0
-46
lines changed

src/main/java/com/fishercoder/solutions/_310.java

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,11 @@
11
package com.fishercoder.solutions;
22

3-
43
import java.util.ArrayList;
54
import java.util.Collections;
65
import java.util.HashSet;
76
import java.util.List;
87
import java.util.Set;
98

10-
/**
11-
* 310. Minimum Height Trees
12-
*
13-
* For a undirected graph with tree characteristics, we can choose any node as the root.
14-
* The result graph is then a rooted tree. Among all possible rooted trees, those with minimum height are called minimum height trees (MHTs).
15-
* Given such a graph, write a function to find all the MHTs and return a list of their root labels.
16-
17-
Format
18-
The graph contains n nodes which are labeled from 0 to n - 1. You will be given the number n and a list of undirected edges (each edge is a pair of labels).
19-
20-
You can assume that no duplicate edges will appear in edges. Since all edges are undirected, [0, 1] is the same as [1, 0] and thus will not appear together in edges.
21-
22-
Example 1:
23-
24-
Given n = 4, edges = [[1, 0], [1, 2], [1, 3]]
25-
26-
0
27-
|
28-
1
29-
/ \
30-
2 3
31-
return [1]
32-
33-
Example 2:
34-
35-
Given n = 6, edges = [[0, 3], [1, 3], [2, 3], [4, 3], [5, 4]]
36-
37-
0 1 2
38-
\ | /
39-
3
40-
|
41-
4
42-
|
43-
5
44-
return [3, 4]
45-
46-
Hint:
47-
48-
How many MHTs can a graph have at most?
49-
Note:
50-
51-
(1) According to the definition of tree on Wikipedia: “a tree is an undirected graph in which any two vertices are connected by exactly one path. In other words, any connected graph without simple cycles is a tree.”
52-
53-
(2) The height of a rooted tree is the number of edges on the longest downward path between the root and a leaf.
54-
*/
559
public class _310 {
5610

5711
public static class Solution1 {

0 commit comments

Comments
 (0)