链表总结
用双指针法找中点:
1.有辅助头结点的:
Head = ListNode(None) #辅助头
Head.next = head #真实头
slow = fast = Head
while fast.next and fast.next.next:
fast = fast.next.next
slow = slow.next2.没有辅助头结点的:
slow = fast = head
pre = None
while fast and fast.next:
pre = slow
fast = fast.next.next
slow = slow.next总结
最后更新于