# 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):
"""
:type head: ListNode
:rtype: ListNode
"""
slow, fast = head, head
while fast and fast.next:
slow = slow.next
fast = fast.next.next
# 如何理解?
if slow == fast:
p = head
q = slow
while p!=q:
p = p.next
q = q.next
#你也可以 return q
return p
return None