【leetcode29】

160. 相交链表

  1. # Definition for singly-linked list.
  2. # class ListNode:
  3. #     def __init__(self, x):
  4. #         self.val = x
  5. #         self.next = None
  6. class Solution:
  7.     def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> Optional[ListNode]:
  8.         a,b=headA,headB
  9.         while a!=b:
  10.             a=a.next if a else headB
  11.             b=b.next if b else headA
  12.         return a
没想到答案这么秒

发表评论