We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 5ca1123 + 2d81332 commit 64552b3Copy full SHA for 64552b3
1 file changed
LeetCode/easy/has_cycle_141.py
@@ -0,0 +1,21 @@
1
+from typing import Optional
2
+
3
4
+class ListNode:
5
+ def __init__(self, x):
6
+ self.val = x
7
+ self.next = None
8
9
10
+class Solution:
11
+ def hasCycle(self, head: Optional[ListNode]) -> bool:
12
+ slow, fast = head, head
13
14
+ while fast and fast.next:
15
+ slow = slow.next
16
+ fast = fast.next.next
17
18
+ if fast == slow:
19
+ return True
20
21
+ return False
0 commit comments