Skip to content

Commit e4d0d1f

Browse files
committed
Sync LeetCode submission Runtime - 46 ms (55.96%), Memory - 19.7 MB (25.14%)
1 parent 265aa30 commit e4d0d1f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

0141-linked-list-cycle/solution.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
# Approach 2 - Floyd's Cycle Finding Algorithm
1+
# Approach 2: Floyd's Cycle Finding Algorithm (Fast and Slow Pointer)
22

3-
# Time: O(n), Space: O(1)
3+
# Time: O(n)
4+
# Space: O(1)
45

56
# Definition for singly-linked list.
67
# class ListNode:
@@ -14,11 +15,12 @@ def hasCycle(self, head: Optional[ListNode]) -> bool:
1415
return False
1516
slow = head
1617
fast = head.next
17-
18+
1819
while slow != fast:
1920
if fast is None or fast.next is None:
2021
return False
2122
slow = slow.next
2223
fast = fast.next.next
23-
24+
2425
return True
26+

0 commit comments

Comments
 (0)