Skip to content

Instantly share code, notes, and snippets.

@dmnugent80
Created January 15, 2015 05:20
Show Gist options
  • Select an option

  • Save dmnugent80/f8f7e0339d570f6a7b4e to your computer and use it in GitHub Desktop.

Select an option

Save dmnugent80/f8f7e0339d570f6a7b4e to your computer and use it in GitHub Desktop.
Write an algorithm to determine if 2 linked lists intersect
public class Node{
int data;
Node next;
public Node(int d){
this.data = d.
this.next = null;
}
}
public boolean doLinkedListsIntersect(Node root1, Node root2){
Node curr1 = root1;
Node curr2 = root2;
while (curr1.next != null){
curr1 = curr1.next;
}
while (curr2.next != null){
curr2 = curr2.next;
}
if (curr1 == curr2){
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment