判断无环链表是否相交思路:若两链表相交,则至少最后一个结点相同。判断两个链表最后结点是否相同来判断是否相交;
public boolean isIntersect(Node head1,Node head2){
if( head1 == null|| head2 == null )
return false;
while(head1.next != null)
head1 = head1.next;
while(head2.next != null)
head2 = head2.next;
if(head1 == head2)
return true;
else
return false;
}