323. Number of Connected Components in an Undirected Graph

time: O(edges*nodes)

space: O(n)

similar to 261

only change this part

and the key idea is

BFS

time: O(m+n), m is edge size(m*2), n is num of node, loop to do bfs

space: O(n)

Last updated

Was this helpful?