题目描述

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

时间限制: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 

 

相关文章:

  • 2022-01-30
  • 2021-06-07
  • 2021-08-19
  • 2021-07-05
  • 2022-12-23
  • 2021-11-12
  • 2022-03-09
  • 2021-12-06
猜你喜欢
  • 2021-06-08
  • 2022-12-23
  • 2021-10-25
  • 2022-01-03
  • 2022-12-23
  • 2021-09-13
  • 2021-11-21
相关资源
相似解决方案