本文共 751 字,大约阅读时间需要 2 分钟。
class Solution(object): def getIntersectionNode(self, headA, headB): """ :type head1, head1: ListNode :rtype: ListNode """ def getLinklen(head): count = 0 while head!= None: count+=1 head=head.next return count lenA=getLinklen(headA) lenB=getLinklen(headB) d = lenB-lenA if d>0: while d>0: headB = headB.next d-=1 if d<0: d=-d while d>0: headA = headA.next d-=1 while headA != None: if headA == headB: break headA=headA.next headB=headB.next return headA
转载地址:http://ggxhj.baihongyu.com/