Skip to content

Commit cb18289

Browse files
Update 'Linked List Cycle'
1 parent b96097d commit cb18289

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ A collection of LeetCode solutions
2020

2121
[Invert Binary Tree](./src/invert_binary_tree.py)
2222

23+
[Linked List Cycle](./src/linked_list_cycle.py)
24+
2325
[Maximum Depth of Binary Tree](./src/maximum_depth_of_binary_tree.py)
2426

2527
[Maximum Subarray](./src/maximum_subarray.py)

src/linked_list_cycle.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
linked list. This algorithm can also be used for directed graphs.
1010
1111
See: https://en.wikipedia.org/wiki/Cycle_detection
12+
13+
This solution has O(n) runtime complexity and O(1) space complexity.
1214
"""
1315

1416
from src.classes import ListNode
@@ -26,7 +28,7 @@ def hasCycle(self, head: ListNode | None) -> bool:
2628
return False
2729

2830
# The algorithm maintains two pointers into the given sequence, one
29-
# (the tortoise) at xi, and the other (the hare) at x2i. At each step
31+
# (the tortoise) at xᵢ, and the other (the hare) at x₂ᵢ. At each step
3032
# of the algorithm, it increases i by one, moving the tortoise one step
3133
# forward and the hare two steps forward in the sequence, and then
3234
# compares the sequence values at these two pointers. The smallest

0 commit comments

Comments
 (0)