Skip to content

Commit 1fd7a6e

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 6a68c34 commit 1fd7a6e

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
@property
22
def has_loop(self) -> bool:
3-
"""
4-
Detect whether the linked list contains a cycle using Floyd's
5-
Cycle-Finding Algorithm (Tortoise and Hare).
3+
"""
4+
Detect whether the linked list contains a cycle using Floyd's
5+
Cycle-Finding Algorithm (Tortoise and Hare).
66
7-
Time Complexity: O(n)
8-
Auxiliary Space: O(1)
9-
"""
10-
slow = self
11-
fast = self.next
7+
Time Complexity: O(n)
8+
Auxiliary Space: O(1)
9+
"""
10+
slow = self
11+
fast = self.next
1212

13-
while fast is not None and fast.next is not None:
14-
if slow is fast:
15-
return True
16-
slow = slow.next
17-
fast = fast.next.next
13+
while fast is not None and fast.next is not None:
14+
if slow is fast:
15+
return True
16+
slow = slow.next
17+
fast = fast.next.next
1818

19-
return False
19+
return False

0 commit comments

Comments
 (0)