[leetcode] Insertion Sort List
来源:互联网 发布:mac 邮件储存位置 编辑:程序博客网 时间:2024/06/08 13:29
题目:
Insertion Sort List
Total Accepted: 10021 Total Submissions: 40511My SubmissionsSort a linked list using insertion sort.
class Solution {public:ListNode *insertionSortList(ListNode *head){if (head == NULL || head->next == NULL) return head;//设置当前遍历指针ListNode * current = head->next;head->next = NULL;//插入排序,head第一个元素就已经排好序ListNode dummy(INT_MIN); dummy.next = head;//小技巧,方便处理while (current != NULL){insert(&dummy, current);//循环插入,时间复杂度O(n2)}return dummy.next;}//插入node到list中,并且设置node为下一个节点void insert(ListNode * list, ListNode * & node){if (node == NULL) return;//查找插入位置while (list->next != NULL){if (list->next->val >= node->val)break;//查找合适的位置list = list->next;}//这四行代码顺序很重要ListNode * next = list->next;list->next = node;node = node->next;list->next->next = next;return;}};
0 0
- Insertion Sort List | leetcode
- Leetcode: Insertion Sort List
- [LeetCode] Insertion Sort List
- Leetcode: Insertion Sort List
- leetcode-Insertion Sort List
- [LeetCode]Insertion Sort List
- 【LeetCode】Insertion Sort List
- LeetCode | Insertion Sort List
- LeetCode - Insertion Sort List
- [LeetCode] Insertion Sort List
- Insertion Sort List (LeetCode)
- [LeetCode] Insertion Sort List
- [LeetCode]Insertion Sort List
- leetcode Insertion Sort List
- Insertion Sort List -- LeetCode
- Insertion Sort List (LeetCode)
- LeetCode Insertion Sort List
- leetcode Insertion Sort List
- Lily系统调查
- Yii的Model ( 模型)创建及使用
- 整理一下 PCI的Memory Mapped IO vs Port IO
- session和cookie的区别
- 用NGUI 显示游戏物体的名字血条
- [leetcode] Insertion Sort List
- Bash脚本15分钟进阶教程
- Unable to add window token null is not for an application
- 完整的windows下搭建Qt开发环境 QT4.8+qt creator2.8.0, 解决 gbd异常中断 和 静态编译
- js DES加密
- JDBC异常总结
- opencv2在直方图反投影算法中使用颜色信息
- android之WebView
- 【数据结构&&算法系列】归并排序简单介绍及python代码