题目描述
输入两个链表,找出它们的第一个公共结点。(注意因为传入数据是链表,所以错误测试数据的提示是用其他方式显示的,保证传入数据是正确的)
# -*- coding:utf-8 -*-# class ListNode:# def __init__(self, x):# self.val = x# self.next = Noneclass Solution:def FindFirstCommonNode(self, pHead1, pHead2):# write code hereif not pHead1 or not pHead2:return Nonep1 = pHead1p2 = pHead2while p1!=p2:if p1:p1 = p1.nextelse:p1 = pHead2if p2:p2 = p2.nextelse:p2 = pHead1return p1
