#141. 环形链表
# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def hasCycle(self, head: ListNode) -> bool: #判断是否存在环,是leetcode142的前提条件 slow, fast = head, head while(fast and fast.next): slow, fast = slow.next, fast.next.next if(slow == fast): return True else: return False