Medium
Count connected components in an undirected graph.
Given n nodes and a list of undirected edges, return the number of connected components.
Examples
Input: n = 5, edges = [[0,1],[1,2],[3,4]]
Output: 2
Constraints
- 0 <= edges.length
Coding Challenge
Count connected components in an undirected graph.
Given n nodes and a list of undirected edges, return the number of connected components.
Input: n = 5, edges = [[0,1],[1,2],[3,4]]
Output: 2
Preparing your coding workspace...