# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None
classSolution: defgetIntersectionNode(self, headA: ListNode, headB: ListNode) -> Optional[ListNode]: a = headA b = headB while a != b: # print(a.val) # print(b.val) if a: a=a.next else: a=headB if b: b=b.next else: b=headA return a