知识点:链表
题目描述:
给一个链表,若其中包含环,请找出该链表的环的入口结点,否则,输出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
if not pHead:
return None
lst = []
while pHead:
if pHead in lst:
return pHead
else:
lst.append