时间复杂度(O(n)),思想:指针位移
# Definition for singly-linked list.
class ListNode(object):
def __init__(self, x):
self.val = x
self.next = None
class Solution:
def getIntersectionNode(self, headA, headB):
pa, pb = headA, headB
while pa != None and pb != None:
pa, pb = pa.next, pb.next
while pa != None:
headA, pa = headA.next, pa.next
while pb != None:
headB, pb = headB.next, pb.next
while headA != headB:
headA, headB = headA.next, headB.next
return headA