Files
PS/leetcode/160.py
Gyubin Han dede0dca01 leetcode
2025-02-19 14:09:55 +09:00

24 lines
497 B
Python

# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> Optional[ListNode]:
al=set()
r=None
a=headA
b=headB
while a:
al.add(a)
a=a.next
while b:
if b in al:
r=b
break
b=b.next
return r