Skip to content

Commit d7dddab

Browse files
committed
Time: 80 ms (61.21%), Space: 17.6 MB (31.08%) - LeetHub
1 parent 2d2d0bf commit d7dddab

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

141-linked-list-cycle/141-linked-list-cycle.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66

77
class Solution:
88
def hasCycle(self, head: Optional[ListNode]) -> bool:
9-
D = {}
10-
temp = head
11-
while temp:
12-
if temp in D:
9+
slow = head
10+
fast = head
11+
while fast and fast.next:
12+
slow = slow.next
13+
fast = fast.next.next
14+
if slow == fast:
1315
return True
14-
else:
15-
D[temp] = None
16-
temp = temp.next
1716
return False
1817

1918

0 commit comments

Comments
 (0)