Click here to see the full article post
@awice Why is the "in" function is set quicker than a "in" of a list?
This ignores the fact that due to the usage of a hash map the given bound is only the expected time complexity. To get "real" O(N + G.length) running time you can build an array as a mask. This is also the reason that the problem description states that the elements in the list are values from [0, N - 1] as opposed to just any integers.
set has O(1) lookup like dictionary
Why is  a connected component in the example below?
The expected answer should be 1 and not 2. Isn't it?
In a list, you need to loop through the list to find a certain element, thus its O(N).
whereas in a HashSet, you find an element by its hashcode, which takes O(1).
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.