insertion sort list刷题 leetcode
来源:互联网 发布:淘宝装修要多少钱 编辑:程序博客网 时间:2024/05/16 05:45
与数组插入不同,链表是断链,单个插入。
设置一个虚指针,始终指向已排序的头,然后不断添加新的数,head始终指向待排序的数
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *insertionSortList(ListNode *head) { ListNode *dummy = new ListNode(0); while (head!=NULL) { ListNode *node = dummy; while (node->next !=NULL && node->next->val < head->val) { node = node->next; } ListNode *t = head; head=head->next; t->next = node->next; node->next = t; } return dummy->next; }};
0 0
- insertion sort list刷题 leetcode
- [LeetCode刷题] Insertion Sort List
- 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)
- Fence Repair
- EPI:Sorting
- Leetcode_Length of Last Word
- 深度搜索C++对象模型2.2 构造函数语义学-Copy Constructor的构造操作
- 韩先聪调离 房产商雇人送行
- insertion sort list刷题 leetcode
- java Arrays.asList()源码剖析
- 根文件系统
- Linux(Ubuntu 12.04)源码编译安装gcc-4.9.1(方法一)——亲自测试通过
- 水上飞机降落水面时险些撞上座头鲸(图)
- php中include和require区别
- POJ 1922
- libgdx Querying (运行时环境属性查询)
- 审计署:2013年全国78亿元保障房专项资金被挪用