链表知识点总结

凡是链表结构发生变化的,都需要 Dummy Node.

链表常用基本功:

• 反转 Reverse

• 归并 Merge
• 找中点 Median

• 增删查改 CRUD

链表查找中点: fast-slow two pointers.

        slow = head
        fast = head
        
        while slow.next and fast.next and fast.next.next:
            slow = slow.next
            fast = fast.next.next
            
        left = head
        right = slow.next
        slow.next = None

以上这种写法:可以稳定的把链表分为左右等长,或者左比右多一个节点的情况。

 

 

posted on 2019-07-13 14:36  Sheryl Wang  阅读(195)  评论(0编辑  收藏  举报

导航