题目描述
一个链表中包含环,请找出该链表的环的入口结点。
思路:题目相对来说比较简单,直接遍历找到第一个曾经出现过得结点就是环的入口,不好的一点是需要借助辅助空间
# -*- coding:utf-8 -*-
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def EntryNodeOfLoop(self, pHead):
pNode = pHead
li = []
while pNode:
if pNode in li:
return pNode
li .append(pNode)
pNode = pNode.next
return None
之后再来补充其他思路