1、题目来源
力扣876题:https://leetcode.cn/problems/middle-of-the-linked-list/
2、解决思路
使用两个指针fast和slow,其中fast每一次移动两步,slow每一次移动一步。
有以下两种情况:
链表的节点数量n为奇数时,当slow指针移动到(n-1)/2时,fast指针移动到n,指向最后一个节点。
链表的节点数量n为偶数时,当slow指针移动到n/2+1时,fast指针移动到n+1,指向一个空值None。
3、代码实现
![](https://img-blog.csdnimg.cn/img_convert/fc52141ab0b0a7f8cbeb15391c80a233.png)
![](https://img-blog.csdnimg.cn/img_convert/484e4745eb6568389cdeb6abae74c2c4.png)