1 Star 1 Fork 1

Clock966 / LeetcodeEveryday

forked from 四方云和 / LeetcodeEveryday 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
InsertionSortList.java 686 Bytes
一键复制 编辑 原始数据 按行查看 历史
RunAtWorld 提交于 2020-03-31 00:18 . Java 语言解答 package
package solution;
public class InsertionSortList {
/**
* 其实很简单,就是从head中每次取一个节点,插到dummy中适当的位置
*/
public ListNode insertionSortList(ListNode head) {
ListNode dummy = new ListNode(0);
for (ListNode next; head != null; head = next) {
next = head.next;
for (ListNode cur = dummy; cur != null; cur = cur.next) {
if (cur.next != null && head.val > cur.next.val) {
continue;
}
head.next = cur.next;
cur.next = head;
break;
}
}
return dummy.next;
}
}
1
https://gitee.com/Clock966/LeetcodeEveryday.git
git@gitee.com:Clock966/LeetcodeEveryday.git
Clock966
LeetcodeEveryday
LeetcodeEveryday
master

搜索帮助