Number of Connected Components in an Undirected Graph(UF and DFS)
Input:
n = 5
and
edges = [[0, 1], [1, 2], [3, 4]]
0 3
| |
1 --- 2 4
Output:
2Input:
n = 5
and
edges = [[0, 1], [1, 2], [2, 3], [3, 4]]
0 4
| |
1 --- 2 --- 3
Output:
1Last updated