Skip to content

Commit 57eceb2

Browse files
committed
0141.Linked List Cycle(python)
1 parent 743098d commit 57eceb2

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Definition for singly-linked list.
2+
# class ListNode(object):
3+
# def __init__(self, x):
4+
# self.val = x
5+
# self.next = None
6+
7+
8+
class Solution(object):
9+
def hasCycle(self, head):
10+
"""
11+
:type head: ListNode
12+
:rtype: bool
13+
"""
14+
slow = fast = head
15+
while fast and fast.next:
16+
slow = slow.next
17+
fast = fast.next.next
18+
if slow == fast:
19+
return True
20+
21+
return False

0 commit comments

Comments
 (0)