【剑指Offer】 55.链表中环的入口结点 python实现

题目描述

给一个链表,若其中包含环,请找出该链表的环的入口结点,否则,输出null。

代码

# -*- coding:utf-8 -*-
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None
class Solution:
    def EntryNodeOfLoop(self, pHead):
        # write code here
 		stack = []
        while pHead:
            stack.append(pHead)
            pHead = pHead.next
            if pHead in stack:
                return pHead
        return
发布了116 篇原创文章 · 获赞 6 · 访问量 6156

猜你喜欢

转载自blog.csdn.net/weixin_42247922/article/details/104071336