难度:简单
一、题目描述:
二、解题分析:
1、剑指解析
2、代码实现
# 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
p = []
q = []
while headA:
p.append(headA)
headA = headA.next
while headB:
q.append(headB)
headB = headB.next
count = -1
target = None
l1 = len(p)
l2 = len(q)
while -count<=l1 and -count<=l2:
if q[count] == p[count]:
target = p[count]
count -= 1
else:
break
return target