[LeetCode] Sort List
来源:互联网 发布:网络连接不上错误651 编辑:程序博客网 时间:2024/05/18 01:02
Sort a linked list in O(n log n) time using constant space complexity.
比较蛋疼,我取巧了。可能不合题意。
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *sortList(ListNode *head) { ListNode *p = head; while(p) { list.push_back(p->val); p = p->next; } sort(list.begin(), list.end()); head = build_list(list); return head; } ListNode *build_list(vector<int> list) { ListNode *head = nullptr, *p = nullptr; for(int i = 0; i < list.size(); i++) { ListNode *tmp = new ListNode(list[i]); if(i == 0) { head = p = tmp; continue; } p->next = tmp; p = tmp; } return head; }private: vector<int> list;};
0 0
- [leetcode][list][sort] Sort List
- Insertion Sort List | leetcode
- Leetcode: Insertion Sort List
- [LeetCode] Insertion Sort List
- Leetcode: Insertion Sort List
- Leetcode: Sort List
- Sort List | leetcode
- leetcode-Sort List
- leetcode-Insertion Sort List
- LeetCode题解:Sort List
- leetcode 134: Sort List
- [LeetCode]Sort List
- [LeetCode]Insertion Sort List
- [LeetCode] Sort List
- 【LeetCode】Insertion Sort List
- leetCode - Sort List
- LeetCode | Insertion Sort List
- LeetCode - Insertion Sort List
- Java NIO框架Netty教程(十四)-Netty中OIO模型(对比NIO)
- Android应用密码的实现
- 字符串匹配的KMP算法
- 关于互联网产品经理有哪些经典书籍?
- 111111111111
- [LeetCode] Sort List
- Django项目的外部访问
- 使用SLComposeViewController 分享图片和文字到FaceBook与Twitter
- 更改移植coco2dx在android上的项目图标
- java内部类
- 关于php静态方法间的调用
- 带通滤波器设计要注意采样率
- mac osx 安装vim python环境
- CocosGUITestMainLayer控件的使用