The article is written in Python 2
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
def hasCycle(head):
	"""
	Floyd's cycle-finding algorithm is a pointer algorithm that uses 2 pointers,
	which move through the sequence at different speeds. 
	"""
	if head is None:
		return False
	rabbit = turtle = head
	while rabbit.next and rabbit.next.next:
		turtle = turtle.next
		rabbit = rabbit.next.next
		if rabbit == turtle:
			return True
		return False