代码
python
# encoding = utf-8
# 开发者:Alen
# 开发时间: 20:16
# "Stay hungry,stay foolish."
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution(object):
def detectCycle(self, head):
seen = set()
node = head
while node:
if node in seen:
return node
seen.add(node)
node = node.next
return None
结果
解题步骤:https://www.bilibili.com/video/BV1SdXxBsEWM/?vd_source=15b4bc8968fa5203cc470cb68ff72c96
