题目描述
输入两个链表,找出它们的第一个公共结点。
代码实现
# -*- coding:utf-8 -*-
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def FindFirstCommonNode(self, pHead1, pHead2):
# write code here
l=[]
while pHead1:
l.append(pHead1)
pHead1=pHead1.next
while pHead2:
if pHead2 in l:
return pHead2
break
pHead2=pHead2.next