——核心思路:快慢指针

——快指针走两步,慢指针走一步

——如果快指针能够追上慢指针,则代表有环

——如果快指针到达终点,则无环

# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

#
# 
# @param head ListNode类 
# @return bool布尔型
#
class Solution:
    def hasCycle(self , head: ListNode) -> bool:
        if(head == None):
            return False
        
        slow = head
        fast = head
        
        while fast != None and fast.next != None:
            fast = fast.next.next
            slow = slow.next
            if(slow == fast):
                return True
        
        return False