Created
April 30, 2018 11:04
-
-
Save amulyakashyap09/66b49e85e5eefcfc4c35566762acb316 to your computer and use it in GitHub Desktop.
Check whether linked lists has cycle or not!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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