Good morning,
for whatever reason the intersectionWithHashing solution is not accepted.
Checking the code with my debugger seems like my solution is fine.
public static <T> SinglyLinkedList<T> intersectionWithHashing(SinglyLinkedList<T> list1, SinglyLinkedList<T> list2) {
Set<T> visited1 = new LinkedHashSet<>();
Set<T> visited2 = new LinkedHashSet<>();
SinglyLinkedList<T>.Node p1 = list1.getHeadNode();
SinglyLinkedList<T>.Node p2 = list2.getHeadNode();
SinglyLinkedList<T> result = new SinglyLinkedList<T>();
result.insertAtHead(null);
while(p1 != null) {
visited1.add(p1.data);
p1 = p1.nextNode;
}
while(p2 != null) {
visited2.add(p2.data);
p2 = p2.nextNode;
}
for (T el: visited1) {
if(visited2.contains(el)) {
result.insertAtEnd(el);
}
}
result.deleteAtHead();
return result;
}
Course: https://www.educative.io/collection/5642554087309312/5724822843686912
Lesson: https://www.educative.io/collection/page/5642554087309312/5724822843686912/5031862374236160