Initialize a HashSet with all the values from nums.
Initialize a variable count to keep track of the number of connected components.
Iterate through the linked list.
a. If the current node's value is in the HashSet and either it's the head of the list or the previous node's value is not in the HashSet, increment count.
b. Continue to the next node.