deffind_mid(lst):assert lst.head isnotNoneand lst.head.nextisnotNone
head = lst.head
fast = head
slow = head
while fast isnotNoneand fast.nextisnotNone:
fast = fast.next.next
slow = slow.nextreturn slow.value
题目查找链表的中间节点思路双指针,一个指针跑两步,另一个指针跑一步,就能找到中间节点。代码def find_mid(lst): assert lst.head is not None and lst.head.next is not None head = lst.head fast = head slow = head while fast is not None and fast.next is not None: fast = fast.next.next