Skip to content

Instantly share code, notes, and snippets.

@amulyakashyap09
Created April 30, 2018 11:04
Show Gist options
  • Save amulyakashyap09/66b49e85e5eefcfc4c35566762acb316 to your computer and use it in GitHub Desktop.
Save amulyakashyap09/66b49e85e5eefcfc4c35566762acb316 to your computer and use it in GitHub Desktop.
Check whether linked lists has cycle or not!
def has_cycle(head):
if head is None:
return False
begin = end = head
while (begin or end or end.next):
if end.next is None:
return False
if begin.next == end.next or begin == end.next.next:
return True
begin = begin.next
end = end.next.next
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment