Skip to content

Instantly share code, notes, and snippets.

@Khamies
Created March 25, 2023 21:56
Show Gist options
  • Save Khamies/37830a6c172a07922bcf490bc72a5d22 to your computer and use it in GitHub Desktop.
Save Khamies/37830a6c172a07922bcf490bc72a5d22 to your computer and use it in GitHub Desktop.
def list_has_cycle(head):
if not head:
return False
fast_p = head.next
slow_p = head
while fast_p:
if slow_p == fast_p:
return True
fast_p = fast_p.next.next
slow_p = slow_p.next
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment