Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7153efd

Browse files
committed
Feat: 876
1 parent 7625e13 commit 7153efd

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /