题目:
题解:
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = Noneclass Solution(object):def detectCycle(self, head):""":type head: ListNode:rtype: ListNode"""a=headi=0dic={}while a:if a in dic:return adic[a]=ii+=1a=a.nextreturn None