题目信息

解题思路

哈希表

快慢指针

代码

  # 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) -> ListNode:
		  if headA == None or headB == None:
			  return None
		  ptA = headA
		  ptB = headB
		  while ptA != None or ptB != None:
			  if ptA == ptB:
				  return ptA
			  if ptA == None:
				  ptA = headB
			  else:
				  ptA = ptA.next
			  if ptB == None:
				  ptB = headA
			  else:
				  ptB = ptB.next
		  return None
	  ```