Faaez Razeen

Linked List Cycle

  • 2 min read
  • LC-Easy
  • Linked List

3 years ago

Solution

TimeSpaceExplanation
O(n)O(1)
def hasCycle(self, head: Optional[ListNode]) -> bool: slow = fast = head while fast and fast.next: slow = slow.next fast = fast.next.next if slow == fast: return True return False