Leetcode | Insertion Sort List | 初出茅庐
来源:互联网 发布:unity3d 材质球shader 编辑:程序博客网 时间:2024/06/07 03:26
Insertion Sort List
Total Accepted: 11143 Total Submissions: 45047My SubmissionsSort a linked list using insertion sort.
这题目比较简单,基本代码一看就明白,试试便知。
/** * 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 *search, *last, *next; if(head == NULL) return head; last = head; while(last->next != NULL) { next = last->next; if(next->val >= last->val) last = last->next; else { if(next->val <= head->val) { last->next = next->next; next->next = head; head = next; } else { search = head; while(next->val > search->next->val) search = search->next; last->next = next->next; next->next = search->next; search->next = next; } } } return head; }};
0 0
- 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)
- LeetCode Insertion Sort List
- 比较函数cmp()
- 美国高手从26美元到创办4家公司的那些事情
- C++类中的static数据成员,static成员函数
- 游戏开发中的一些基本方法
- 堆栈实现(C++)
- Leetcode | Insertion Sort List | 初出茅庐
- leetcode Combination Sum
- hdu1013
- TI样片申请问题个人见解
- 幸运数字
- ImageSwitcher
- ----------------http://blog.sina.com.cn/s/blog_5da93c8f0101hnzx.html
- makefile中自动化变量
- --------------Activity onNewIntent 方法调用时机