題目描述
輸入兩個鏈表,找出它們的第一個公共結點。
代碼實現
# -*- 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