Skip to content

Commit 77fc206

Browse files
committed
876
1 parent b4c8c1f commit 77fc206

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

LL/876.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## Middle of the Linked List
2+
3+
#### Description
4+
5+
[link](https://leetcode.com/problems/middle-of-the-linked-list/)
6+
7+
---
8+
9+
#### Solution
10+
11+
- See Code
12+
13+
---
14+
15+
#### Code
16+
17+
O(n)
18+
19+
```python
20+
# Definition for singly-linked list.
21+
# class ListNode:
22+
# def __init__(self, val=0, next=None):
23+
# self.val = val
24+
# self.next = next
25+
class Solution:
26+
def middleNode(self, head: ListNode) -> ListNode:
27+
fast = head
28+
slow = head
29+
while fast.next and fast.next.next:
30+
slow = slow.next
31+
fast = fast.next.next
32+
return slow .next if fast.next else slow
33+
```

0 commit comments

Comments
 (0)