题目描述: 编写一个程序,找到两个单链表相交的起始结点。
def getIntersectionNode(self,headA,headB):
" " "
:type head1,head:ListNode
:rtype: ListNode
" " "
a=headA
b=headB
i=0
l=m=0
while a:
a=a.next
l+=1
while b:
b=b.next
m+=1
if a!=b:
return None
a=headA
b=headB
if l>m:
diff=l-m
while diff:
a=a.next
diff-=1
if l<m:
diff=m-l
while diff:
b=b.next
diff-=1
while a!=b:
a=a.next
b=b.next
return a