We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
staticintfindMergeNode(SinglyLinkedListNodehead1,SinglyLinkedListNodehead2){//use two ptrs to track head1 and head2SinglyLinkedListNodefirst=head1;SinglyLinkedListNodesecond=head2;while(first!=second){first=(first.next!=null)?first.next:head2;second=(second.next!=null)?second.next:head1;}returnfirst!=null?first.data:-1;//no merge node found}
Cookie support is required to access HackerRank
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 →
My Java solution with o(n) time and o(1) space: