# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def hasCycle(self, head):
# write your code here
if head is None:
return False
if head.next is None:
return False
slow = head.next
fast = head.next
if fast.next is not None:
fast = fast.next
while (slow.next is not None) and (fast.next is not None):
if slow == fast:
return True
slow = slow.next
fast = fast.next
if fast.next != None:
fast = fast.next
return False