8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7625e13 commit 7153efdCopy full SHA for 7153efd
problems/876-middle-of-the-linked-list.md
@@ -0,0 +1,32 @@
1
+## 题目
2
+
3
+* 876. 链表的中间结点
4
5
+给定一个头结点为 head 的非空单链表,返回链表的中间结点。
6
7
+如果有两个中间结点,则返回第二个中间结点。
8
9
+## 思路
10
11
+快慢指针。
12
13
+## 代码
14
15
+```php
16
+class Solution {
17
18
+ /**
19
+ * @param ListNode $head
20
+ * @return ListNode
21
+ */
22
+ function middleNode($head) {
23
+ $slow = $head;
24
+ $fast = $head;
25
+ while ($fast && $fast->next) {
26
+ $slow = $slow->next;
27
+ $fast = $fast->next->next;
28
+ }
29
+ return $slow;
30
31
+}
32
+```
0 commit comments