You are viewing a single comment's thread. Return to all comments →
BRUTE FORCE Approach
static int findMergeNode(SinglyLinkedListNode head1, SinglyLinkedListNode head2) { HashMap<SinglyLinkedListNode, Integer> map = new HashMap<>(); SinglyLinkedListNode temp1 = head1; SinglyLinkedListNode temp2 = head2; while(temp1 != null) { map.put(temp1, 1); temp1 = temp1.next; } while(temp2 != null) { if(map.containsKey(temp2)) { return temp2.data; } else{ map.put(temp2, 1); temp2 = temp2.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 →
BRUTE FORCE Approach