leetcode 148. Sort List
来源:互联网 发布:apache虚拟主机不生效 编辑:程序博客网 时间:2024/05/16 02:02
class Solution {public:ListNode* sortList(ListNode* head){if (head == nullptr || head->next == nullptr){return head;}auto fast = head->next->next, slow = head;while (fast && fast->next){slow = slow->next;fast = fast->next->next;}auto head2 = sortList(slow->next);slow->next = nullptr;return merge(sortList(head), head2);}private:ListNode* merge(ListNode* h1, ListNode* h2){auto DummyHead = new ListNode(0);auto head = DummyHead;while (h1 && h2){if (h1->val < h2->val){head->next = h1;h1 = h1->next;}else{head->next = h2;h2 = h2->next;}head = head->next;}head->next = (h1 == nullptr) ? h2 : h1;return DummyHead->next;}};
0 0
- LeetCode 148. Sort List
- [LeetCode]148.Sort List
- [leetcode] 148.Sort List
- 148. Sort List LeetCode
- Leetcode 148. Sort List
- LeetCode *** 148. Sort List
- LeetCode 148. Sort List
- leetcode.148. Sort List
- LeetCode-148.Sort List
- [Leetcode] 148. Sort List
- 148. Sort List --- leetcode
- LeetCode - 148. Sort List
- leetcode 148. Sort List
- Leetcode 148. Sort List
- [LeetCode] 148. Sort List
- Leetcode-148. Sort List
- LeetCode 148. Sort List
- [LeetCode]148. Sort List
- BZOJ 1683: [Usaco2005 Nov]City skyline 城市地平线 还是单调栈。。。
- 什么是存储转发技术
- SSL 1636——城市交通
- 数据库外键的使用
- 花拉子模信使问题(王小波)
- leetcode 148. Sort List
- Jquery——Day4(Ajax基本用法get/post/ajax/serialize等)
- 城市交通-SSL 1636
- jQuery延迟函数 让DIV延时几秒后消失或显示
- IOS缓存管理之PINCache使用
- 网站一定要增加友情链接吗?
- 【C#基础】——初识
- 冒泡法排序
- 100. Same Tree