Skip to content

Commit 385bbb1

Browse files
committed
update readme
1 parent f5fba84 commit 385bbb1

File tree

5 files changed

+32
-191
lines changed

5 files changed

+32
-191
lines changed

0142-linked-list-cycle-ii/0142-linked-list-cycle-ii.py

Lines changed: 0 additions & 53 deletions
This file was deleted.

3616-make-array-elements-equal-to-zero/3616-make-array-elements-equal-to-zero.py

Lines changed: 0 additions & 41 deletions
This file was deleted.

3616-make-array-elements-equal-to-zero/README.md

Lines changed: 0 additions & 69 deletions
This file was deleted.

Python/0142-linked-list-cycle-ii.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
# time complexity: O(n)
2+
# space complexity: O(n)
3+
from typing import Optional
14

25

6+
class ListNode:
7+
def __init__(self, x):
8+
self.val = x
9+
self.next = None
10+
311

412
class Solution:
513
def detectCycle(self, head: Optional[ListNode]) -> Optional[ListNode]:
@@ -12,6 +20,30 @@ def detectCycle(self, head: Optional[ListNode]) -> Optional[ListNode]:
1220
node = node.next
1321
return None
1422

23+
# time complexity: O(n)
24+
# space complexity: O(1)
25+
class Solution:
26+
def detectCycle(self, head: Optional[ListNode]) -> Optional[ListNode]:
27+
slow = head
28+
fast = head
29+
30+
while fast and fast.next:
31+
slow = slow.next
32+
fast = fast.next.next
33+
34+
if slow == fast:
35+
break
36+
37+
if not fast or not fast.next:
38+
return None
39+
40+
fast = head
41+
42+
while slow != fast:
43+
slow = slow.next
44+
fast = fast.next
45+
46+
return slow
1547

1648
head = ListNode(3)
1749
head.next = ListNode(2)

README.md

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -115,31 +115,3 @@ It helps others discover the repo and keeps the project growing.
115115
---
116116

117117
Feedback / Questions → open an Issue or reach out on [LinkedIn](https://www.linkedin.com/in/hogan-l/)
118-
119-
<!---LeetCode Topics Start-->
120-
# LeetCode Topics
121-
## Array
122-
| |
123-
| ------- |
124-
| [3616-make-array-elements-equal-to-zero](https://github.com/hogan-tech/leetcode-solution/tree/master/3616-make-array-elements-equal-to-zero) |
125-
## Simulation
126-
| |
127-
| ------- |
128-
| [3616-make-array-elements-equal-to-zero](https://github.com/hogan-tech/leetcode-solution/tree/master/3616-make-array-elements-equal-to-zero) |
129-
## Prefix Sum
130-
| |
131-
| ------- |
132-
| [3616-make-array-elements-equal-to-zero](https://github.com/hogan-tech/leetcode-solution/tree/master/3616-make-array-elements-equal-to-zero) |
133-
## Hash Table
134-
| |
135-
| ------- |
136-
| [0142-linked-list-cycle-ii](https://github.com/hogan-tech/leetcode-solution/tree/master/0142-linked-list-cycle-ii) |
137-
## Linked List
138-
| |
139-
| ------- |
140-
| [0142-linked-list-cycle-ii](https://github.com/hogan-tech/leetcode-solution/tree/master/0142-linked-list-cycle-ii) |
141-
## Two Pointers
142-
| |
143-
| ------- |
144-
| [0142-linked-list-cycle-ii](https://github.com/hogan-tech/leetcode-solution/tree/master/0142-linked-list-cycle-ii) |
145-
<!---LeetCode Topics End-->

0 commit comments

Comments
 (0)