Created
May 21, 2022 04:42
-
-
Save thekhairul/be1fd6f90de39099a089550e489b36e3 to your computer and use it in GitHub Desktop.
Leetcode 141: Linked List Cycle - python
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 hasCycle(head): | |
fast, slow = head, head | |
while fast and fast.next: | |
fast = fast.next.next | |
slow = slow.next | |
if fast == slow: | |
return True | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment