You are viewing a single comment's thread. Return to all comments →
The key idea to check the the same object is exist in the set
static int findMergeNode(SinglyLinkedListNode head1, SinglyLinkedListNode head2) { Set<SinglyLinkedListNode> nodeSet = new HashSet<>(); SinglyLinkedListNode currh1 = head1; SinglyLinkedListNode currh2 = head2; while(currh1 != null){ nodeSet.add(currh1); currh1 = currh1.next; } while(currh2 != null){ if(nodeSet.contains(currh2)){ return currh2.data; } currh2 = currh2.next; } return -1; }
Seems like cookies are disabled on this browser, please enable them to open this website
Find Merge Point of Two Lists
You are viewing a single comment's thread. Return to all comments →
The key idea to check the the same object is exist in the set