LeetCode ๐๏ธ/Graph
33. Number of Connected Components in an Undirected Graph
Description: Solution:
Description: Solution:
Description: Solution: Sorthing is O(nlogn), so we need a solution for O(n) if (n - 1) not in numSet, it would be the first start point of sequence. In while loop, we keep add the length by 1 to see how long the sequence is. And then, return the longest sequence. Time Complexity: O(n) Space Complexity: O(n)
Description: Solution: Time Complexity: O(nm)