其他分享
首页 > 其他分享> > 160 intersection of two linkedlist

160 intersection of two linkedlist

作者:互联网

题目:找到两个linkedlist起始交集部分

 

如果没有交集,推出

O(1)

 

 


public class solution{
public ListNode getIntersect(ListNode headA, ListNode headB){
if(headA==null||headB==null) return null;

ListNode a= headA;
ListNode b=headB;

while(a!=b){
a=a==null?headB:a.next;
b=b==null?headA:b.next;
}
return a;
}
}

标签:intersection,ListNode,linkedlist,two,headB,headA,return,null,160
来源: https://www.cnblogs.com/LLflag1/p/16468580.html