Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions LeetCode/easy/has_cycle_141.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from typing import Optional


class ListNode:
def __init__(self, x):
self.val = x
self.next = None


class Solution:
def hasCycle(self, head: Optional[ListNode]) -> bool:
slow, fast = head, head

while fast and fast.next:
slow = slow.next
fast = fast.next.next

if fast == slow:
return True

return False
Loading