Detecting a loop in a Linked list using a hashset
I think instead of adding integers to the Hashset, what we should do is insert a LinkedListNode instance into the Hashset and then to detect a loop we check whether the current node exists in the Hashset or not, if it does then there's a loop

 HashSet&lt;LinkedListNode&gt; set = new HashSet&lt;LinkedListNode&gt;();
    LinkedListNode current = head;
    while(current != null) {
        if(current.next != null) {
            if(set.contains(current.next)) {
                return current.next; // this has been seen so there is a loop.
            }
            set.add(current.next);
        }
        current = current.next;
    }
    return null;