LeetCode 147 Insertion Sort List
来源:互联网 发布:算法导论 python 编辑:程序博客网 时间:2024/04/28 22:17
题目描述
Sort a linked list using insertion sort.
代码
public ListNode insertionSortList(ListNode head) { if (head == null) return null; if (head.next == null) return head; final ListNode _head = new ListNode(Integer.MIN_VALUE); _head.next = head; head = head.next; _head.next.next = null; next: while (head != null) { ListNode taken = head; head = head.next; ListNode cur = _head.next; ListNode last = _head; while (cur != null) { if (cur.val > taken.val) { // insert last.next = taken; taken.next = cur; continue next; } cur = cur.next; last = last.next; } last.next = taken; taken.next = null; } return _head.next; }
1 0
- LeetCode(147) Insertion Sort List
- LeetCode: Insertion Sort List [147]
- LeetCode 147 Insertion Sort List
- [leetcode 147] Insertion Sort List
- LeetCode 147 Insertion Sort List
- LeetCode 147 Insertion Sort List
- [leetcode 147]Insertion Sort List
- leetcode-147 Insertion Sort List
- [LeetCode 147]Insertion Sort List
- Leetcode[147]-Insertion Sort List
- Insertion Sort List - LeetCode 147
- leetcode[147]:Insertion Sort List
- LeetCode(147) Insertion Sort List
- leetcode 147: Insertion Sort List
- [Leetcode]#147 Insertion Sort List
- leetCode #147 Insertion Sort List
- LeetCode 147 Insertion Sort List
- LeetCode 147:Insertion Sort List
- 记一个百度地图导航中存在的bug
- oracle数据库表查询,空间查询
- iOS 万能跳转界面方法 (runtime实用篇一)
- WIN10通用技术开发之Universal Windows App
- Android开发屏幕适配全攻略
- LeetCode 147 Insertion Sort List
- 关于rocks的一些网址
- java中转发和重定向的区别
- netcat在两台linux间传递大文件
- HTML框架
- tomcat的虚拟路径配置【最牛逼】办法
- Linux任务控制(bg job fg nohup &)
- OC一些宏定义
- openwrt计划任务不执行故障排除