LeetCode--Insertion Sort List
来源:互联网 发布:淘宝售后评价回复 编辑:程序博客网 时间:2024/05/16 14:48
Sort 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) {if(head==NULL || head->next==NULL)return head; ListNode* temp = head->next;ListNode* pre = head;while(temp!=NULL){if(temp->val < pre->val){head = insert(head,pre,temp);temp = pre->next;}else{ temp = temp->next; pre = pre->next;}}return head; }ListNode* insert(ListNode* head, ListNode* pre, ListNode* inser){ListNode* temp = head;ListNode* save = head;while(temp->val <= inser->val){save = temp;temp = temp->next;}pre->next = inser->next;inser->next = temp;if(temp == head)head = inser;elsesave->next = inser;return head;}};
1 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
- 族综嘴综拙啄仔注撰滓租足状走妆尊姿转
- Dubbo基本原理机制-超时、注册
- Android 快速开发开源框架
- 【Android开发经验】ViewHolder到底用什么修饰?static?final?static final?
- Struts2学习 动态方法调用(DMI)
- LeetCode--Insertion Sort List
- Ant命令行参数
- 微信运营怎么做,听高手透露秘诀
- Android 创世纪系列
- java设计模式--事件监听器模式和观察者模式
- tcp_keepalive设置
- 锥作字走爪昨纵座做坠祖赘滓桌赚租遵着
- CentOS6.6下安装配置nfs
- nginx负载均衡