# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
#
#
# @param pHead1 ListNode类
# @param pHead2 ListNode类
# @return ListNode类
#
class Solution:
def FindFirstCommonNode(self , pHead1 , pHead2 ):
# write code here
"""
l = []
if not pHead1 or not pHead2:
return None
else:
while pHead1 != None:
l.append(pHead1.val)
while pHead2 != None:
if pHead2.val in l:
break
else:
pHead2 = pHead2.next
return pHead2
"""
if not pHead1 or not pHead2:
return None
else:
while pHead1:
p = pHead2
while p:
if p.val == pHead1.val and p.next == pHead1.next:
return p
break
else:
p = p.next
pHead1 = pHead1.next
return None