Insertion Sort List
来源:互联网 发布:python给字典添加新值 编辑:程序博客网 时间:2024/05/22 15:32
public class Solution { public ListNode insertionSortList(ListNode head) { if (head == null) { return null; } ListNode newHeadNode = new ListNode(head.val); head = head.next; while (head != null) { ListNode insertNode = new ListNode(head.val); ListNode prev = null; ListNode cur = newHeadNode; while (cur != null) { if (insertNode.val < cur.val) {if (prev == null) {insertNode.next = cur;newHeadNode = insertNode;break;}else {prev.next = insertNode;insertNode.next = cur;break;}} else { prev = cur; cur = cur.next; } } if (cur == null) {prev.next = insertNode;insertNode.next = null;} head = head.next; } return newHeadNode; }}
Sort a linked list using insertion sort.
Nothing much to explain. Just be careful when you insert this node at the beginning or at the end.
0 0
- Insertion Sort List | leetcode
- Leetcode: Insertion Sort List
- [LeetCode] Insertion Sort List
- Insertion Sort List
- Leetcode: Insertion Sort List
- [LeeCode] Insertion Sort List
- leetcode-Insertion Sort List
- [LeetCode]Insertion Sort List
- Insertion Sort List
- 【LeetCode】Insertion Sort List
- LeetCode | Insertion Sort List
- LeetCode - Insertion Sort List
- Insertion Sort List
- Insertion Sort List
- Insertion Sort List
- Insertion Sort List
- [LeetCode] Insertion Sort List
- list - insertion sort - AC
- leetcode: Balanced Binary Tree
- 类似QQ电脑空闲5分钟后自动更改状态的实现
- poj3083
- 用Scribefire发CSDN博客
- c#delegate应用
- Insertion Sort List
- 编写高质量代码——reintepret_cast、static_cast、dynamic_cast、const_cast
- Firefox中利用javascript调用本地程序
- 乡村与城市摘录
- TCP/IP卷一 第三章IP网际协议 个人摘抄
- iOS 关于 UIKit 专栏应该写在最前面的话
- Effective C++ 笔记
- sqli-labs ---- Less-7
- cocos2dx 3.0打包android遇到的错误(持续更新)