【剑指Offer】36两个链表的第一个公共结点

题目描述

输入两个链表,找出它们的第一个公共结点。

时间限制:1秒;空间限制:32768K;本题知识点:链表

解题思路

# -*- 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
        p1 = pHead1
        while p1!=None:
            p2 = pHead2
            while p2!=None:
                if p1 == p2: #公共节点不等于有相同值的节点
                    return p1
                p2 = p2.next
            p1 = p1.next
        return 
原文地址:https://www.cnblogs.com/yucen/p/9912026.html