# Definition for singly-linked list.# class ListNode:# def __init__(self, x):# self.val = x# self.next = NoneclassSolution:defhasCycle(self,head: ListNode) ->bool: fast = head slow = headwhile fast and fast.next: fast = fast.next.next slow = slow.nextif fast == slow:returnTruereturnFalse