323. Number of Connected Components in an Undirected Graph

Problem

Find the number of connected components in an undirected graph with n nodes and given edges.

Given n nodes (0 to n-1) and a list of undirected edges, find the number of connected components in the graph.

A connected component is a maximal set of vertices where every vertex is reachable from every other vertex in the set.

Examples
Input: [5,[[0,1],[1,2],[3,4]]]
Output: 2
Hints
Related Problems

323. Number of Connected Components in an Undirected Graph

Find the number of connected components in an undirected graph with n nodes and given edges.