[LeetCode]147. Insertion Sort List链表排序
插入排序的基本思想
把排好的放在一个新的变量中,每次拿出新的,排进去
这个新的变量要有超前节点,因为第一个节点可能会有变动
public ListNode insertionSortList(ListNode head) {
if (head==null||head.next==null) return head;
ListNode dummy = new ListNode(0);
ListNode h = head;
ListNode next;
ListNode temp;
while (h!=null)
{
next = h.next;
temp = dummy;
while (temp.next!=null&&h.val>temp.next.val) {
temp = temp.next;
}
h.next = temp.next;
temp.next = h;
h = next;
}
[LeetCode]147. Insertion Sort List链表排序的更多相关文章
- [LeetCode] 147. Insertion Sort List 链表插入排序
Sort a linked list using insertion sort. A graphical example of insertion sort. The partial sorted l ...
- LeetCode 147. Insertion Sort List 链表插入排序 C++/Java
Sort a linked list using insertion sort. A graphical example of insertion sort. The partial sorted l ...
- [LeetCode] 147. Insertion Sort List 解题思路
Sort a linked list using insertion sort. 问题:实现单向链表的插入排序. 这是比较常规的一个算法题目. 从左往右扫列表,每次将指针的下一个元素插入前面已排好序的 ...
- Java for LeetCode 147 Insertion Sort List
Sort a linked list using insertion sort. 解题思路: 插入排序,JAVA实现如下: public ListNode insertionSortList(List ...
- leetcode 147. Insertion Sort List ----- java
Sort a linked list using insertion sort. 插入排序. /** * Definition for singly-linked list. * public cla ...
- 147 Insertion Sort List 链表插入排序
用插入排序对链表进行排序. 详见:https://leetcode.com/problems/insertion-sort-list/description/ Java实现: 链表的插入排序实现原理很 ...
- 147.Insertion Sort List---链表排序(直接插入)
题目链接 题目大意:对链表进行插入排序. 解法:直接插入排序.代码如下(耗时40ms): public ListNode insertionSortList(ListNode head) { List ...
- Leetcode#147 Insertion Sort List
原题地址 心得:有关链表的题目,多用中间变量,代码写得清晰一点,适当注释 代码: ListNode *insertionSortList(ListNode *head) { if (!head) re ...
- [leetcode] 147. Insertion Sort List (Medium)
原题 别人的思路 非常简洁 function ListNode(val) { this.val = val; this.next = null; } /** * @param {ListNode} h ...
随机推荐
- Linux无法新增用户
1.查看当前用户是否有权限创建用户 2.磁盘空间不足,vi打开/etc/passwd 报: E297: Write error in swap file"adduser.sh" 1 ...
- java集合源码分析(三):ArrayList
概述 在前文:java集合源码分析(二):List与AbstractList 和 java集合源码分析(一):Collection 与 AbstractCollection 中,我们大致了解了从 Co ...
- MiniProfiler性能监控分析工具在.NET项目中的使用
MiniProfiler是一款针对.NET, Ruby, Go and Node.js的性能分析的轻量级程序.可以对一个页面本身,及该页面通过直接引用.Ajax.Iframe形式访问的其它页面进行监控 ...
- jupyter notebook 安装记录
conda install jupyterconda install jupyter_nbextensions_configuratorconda install jupyter_contrib_nb ...
- PyQt学习随笔:QTableWidget项sizeHint的作用以及与QHeadView的sectionResizeMode、ResizeToContents的关系
老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 在学习QTableWidgetItem的sizeHint()方法时,Qt自带材料中介绍sizeHin ...
- john快速破解各种散列hash
0x01 john工具安装: kali系统自带的有,也可以自己安装在其他linux和windows系统上,关于安装步骤网上都有可自行百度. 0x02 john常用选项 具体的其他选项可通过john - ...
- 原生JS学习之秒表、日历
Tips:涉及知识点:Date setInterval DOM 秒表 效果图: 简单构造出草图 Html代码 1 <!DOCTYPE html> 2 <html> ...
- vue props默认值国际化报错
未做国际化处理 tabLabel: { type: Array, default: () => (["a", "b", "c"]) } ...
- Java8新增的这些集合骚操作,你掌握了嘛?
目录 Iterable的forEach Iterator的forEachRemaining Collection的removeIf Stream操作 List的replaceAll List的sort ...
- rman catalog配置
1.创建表空间 create tablespace rman_tbs datafile '/u01/app/oracle/oradata/PROD1/rman_tbs01.dbf' size 200m ...