We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c99944e commit 7101623Copy full SHA for 7101623
Fast & Slow Pointers/Easy/Linked List Cycle.py
@@ -0,0 +1,19 @@
1
+# Definition for singly-linked list.
2
+# class ListNode:
3
+# def __init__(self, x):
4
+# self.val = x
5
+# self.next = None
6
+
7
+class Solution:
8
+ def hasCycle(self, head: ListNode) -> bool:
9
+ if not head:
10
+ return False
11
12
+ slow, fast = head, head.next
13
+ while slow != fast:
14
+ if fast is None or fast.next is None:
15
16
+ slow = slow.next
17
+ fast = fast.next.next
18
19
+ return True
0 commit comments