Created
March 25, 2023 21:56
-
-
Save Khamies/37830a6c172a07922bcf490bc72a5d22 to your computer and use it in GitHub Desktop.
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 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