Skip to content

Commit a1eb219

Browse files
authoredDec 26, 2021
Create 141-Linked-List-Cycle.py
1 parent ce5816d commit a1eb219

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
 

‎141-Linked-List-Cycle.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
slow, fast = head, head
10+
11+
while fast and fast.next:
12+
slow = slow.next
13+
fast = fast.next.next
14+
if slow == fast:
15+
return True
16+
return False

0 commit comments

Comments
 (0)
Please sign in to comment.