Reproduced in: http://blog.csdn.net/happymatilian/article/details/47811161
Ideas:
Linked lists have linked lists and non-linked lists, if there are two linked lists Intersect, there are only two possible, two linked lists have no ring or have a ring.
(1) If the list is not ring, then first determine whether the list of the tail pointer is the same, if not the same, there is no intersection. If the same, then find out the length of the two linked lists, the two linked list from the same distance from the tail node scan, if the intersection, there must be a scan node the same. Instance data List1:1->2->3->4->5->6->7->null,list2:0->9->8->6->7->null, the first intersect node is 6
The example diagram is as follows
(2) If the list has a ring, then only the following two cases (such as) can be. The two cases are differentiated by whether the inbound points are the same.
If the same is the first case: then finding the first intersection point is the same as the method of finding the first intersection at the intersection of a single linked list without loops.
If the inbound point is different, then the second case, the intersection point either for the List1 point of the LOOP1 or for the List2 's inbound point loop2.
Case 1 Instance data (list1:1->2->3->4->5->6->7->4,list2:0->9->8->2->3->4->5->6- >7->4, the first intersection is 2)
Case 2 Instance data (list1:1->2->3->4->5->6->7->4,list2:0->9->8->6->7->4->5-> 6, the first intersection is 4 or 6)
 Public Static classNode { Public intvalue;  PublicNode Next;  PublicNode (intdata) {               This. Value =data; }      }  /*determine if intersect, if intersect, get first intersection point*/       Public Staticnode Getintersectnode (node Head1, node head2) {if(Head1 = =NULL|| Head2 = =NULL) {              return NULL; } Node Loop1=Getloopnode (HEAD1); Node LOOP2=Getloopnode (head2); if(Loop1 = =NULL&& LOOP2 = =NULL) {              returnNoloop (Head1, head2); }          if(Loop1! =NULL&& LOOP2! =NULL) {              returnBothloop (Head1, Loop1, head2, LOOP2); }          return NULL; }  /** Determine if there is a ring, and if so, find the entry point of the ring.  * Entry point to find the method: Fast and slow hands, block hands walk two steps, full pointer to step, if there is a loop, then the slow pointer before the loop, always and the quick pointer meet. * Go backwards at the same time from the point of the head and meet, the point of meeting must be the entry point. */       Public Staticnode Getloopnode (node head) {if(Head = =NULL|| Head.next = =NULL|| Head.next.next = =NULL) {              return NULL; } Node N1= Head.next;//N1-SlowNode n2 = Head.next.next;//N2-Fast         while(N1! =n2) {              if(N2.next = =NULL|| N2.next.next = =NULL) {                  return NULL; } n2=N2.next.next; N1=N1.next; } n2= head;//N2-Walk again from head         while(N1! =n2) {N1=N1.next; N2=N2.next; }          returnN1; }  /*the method of judging without ring*/       Public Staticnode Noloop (node Head1, node head2) {if(Head1 = =NULL|| Head2 = =NULL) {              return NULL; } Node Cur1=Head1; Node CUR2=head2; intn = 0;  while(Cur1.next! =NULL) {n++; Cur1=Cur1.next; }           while(Cur2.next! =NULL) {n--; CUR2=Cur2.next; }          if(Cur1! =CUR2) {              return NULL; } cur1= n > 0?head1:head2; CUR2= Cur1 = = Head1?Head2:head1; N=Math.Abs (n);  while(n! = 0) {n--; Cur1=Cur1.next; }           while(Cur1! =CUR2) {Cur1=Cur1.next; CUR2=Cur2.next; }          returnCur1; }  /*the method of judging when there is ring*/[Java] View plain copy Public Staticnode Bothloop (node Head1, node Loop1, node head2, node Loop2) {node Cur1=NULL; Node CUR2=NULL; if(Loop1 = =loop2) {Cur1=Head1; CUR2=head2; intn = 0;  while(Cur1! =LOOP1) {N++; Cur1=Cur1.next; }               while(CUR2! =loop2) {N--; CUR2=Cur2.next; } cur1= n > 0?head1:head2; CUR2= Cur1 = = Head1?Head2:head1; N=Math.Abs (n);  while(n! = 0) {n--; Cur1=Cur1.next; }               while(Cur1! =CUR2) {Cur1=Cur1.next; CUR2=Cur2.next; }              returnCur1; } Else{Cur1=Loop1.next;  while(Cur1! =LOOP1) {                  if(Cur1 = =loop2) {                      returnLoop1; } cur1=Cur1.next; }              return NULL; }      }  
Java determines if two single-linked lists Intersect