876. 链表的中间结点
来源: 876. 链表的中间结点
1. 解题思路
利用快慢指针
2. 代码
class Solution:
def middleNode(self, head: ListNode) -> ListNode:
fast, slow = head, head
while(fast and fast.next):
fast = fast.next.next
slow = slow.next
return slow