Leetcode习题:Insertion Sort List
来源:互联网 发布:淘宝怎么增加自然流量 编辑:程序博客网 时间:2024/06/16 14:21
Insertion Sort List
Total Accepted: 2832 Total Submissions: 11108My SubmissionsSort a linked list using insertion sort.
public class Solution { public ListNode insertionSortList(ListNode head) { if (head == null) { return null; } ListNode p1 = head.next; head.next = null; while (p1 != null) { ListNode prev = null; ListNode p2 = head; while (p2!=null && p2 != p1 && p2.val < p1.val) { prev = p2; p2 = p2.next; } ListNode next = p1.next; if(p2 == null){ prev.next = p1; p1.next = null; }else if (prev == null) {// head p1.next = head; head = p1; }else { p1.next = prev.next; prev.next = p1; } p1 = next; } return head; } }
0 0
- Leetcode习题:Insertion Sort List
- 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
- 鼠标悬浮
- 创业公司如何实施敏捷开发
- Oracle客户端出现乱码的解决
- vs2012调试JS
- 模板偏特化
- Leetcode习题:Insertion Sort List
- Java面试题集(71-85)
- android.view.InflateException
- linux下获取本机ip地址,ipv4和ipv6
- sig_atomic_t
- 黑马程序员_反射
- hdu-2546 饭卡 01背包
- 百度地图静态图之坐标转换
- jsp页面不能显示图片问题