![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
List
链表常见操作
without honor
这个作者很懒,什么都没留下…
展开
-
链表的归并排序
class Solution { public: ListNode* sortList(ListNode* head) { if(!head||!head->next)return head; return mergeSort(head); } ListNode*mergeSort(ListNode* head){ if...原创 2020-01-31 20:23:58 · 61 阅读 · 0 评论 -
LeetCode 143:重排链表
找到中点,反转后一半,合并前后 class Solution { public: void reorderList(ListNode* head) { if(head==nullptr||head->next==nullptr){ return; } ListNode* slow=head; L...原创 2020-01-30 16:41:58 · 97 阅读 · 0 评论 -
LeetCode 86: partition list
method 1: 使用两个空头结点记录 ListNode* partition(ListNode* head, int x) { ListNode*before_head=new ListNode(0); ListNode*before=before_head; ListNode*after_head=new ListNode(0); ...原创 2020-01-28 10:46:06 · 71 阅读 · 0 评论 -
反转链表
ListNode* reverseList(ListNode* head) { ListNode*pre=NULL; ListNode*post=NULL; if(!head)return head; post=head->next; while(post){ head->next...原创 2020-01-27 22:54:28 · 68 阅读 · 0 评论