from utils.listNode import ListNode

class Solution:
    def has_cycle(self, head):
        if not head or not head.next:
            return False

        slow, fast = head.next, head.next.next

        while fast and fast.next:
            if fast == slow:
                return True
            
            slow = slow.next
            fast = fast.next.next
        
        return False


one = ListNode(1)
two = ListNode(2)
three = ListNode(3)
four = ListNode(4)
five = ListNode(5)
six = ListNode(6)
seven = ListNode(7)

one.next = two
two.next = three
three.next = four
four.next = five
five.next = six
six.next = three

solution = Solution()
print(solution.has_cycle(one))