Insertion Sort List
来源:互联网 发布:mac qq截图不能用 编辑:程序博客网 时间:2024/05/20 23:37
Q:
Sort a linked list using insertion sort.
Solution:
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public class Solution { public ListNode insertionSortList(ListNode head) { if (head == null) return head; ListNode cur = head.next; while (cur != null) { ListNode temp = head; while (temp.val <= cur.val && temp != cur) temp = temp.next; if (temp != cur) { while (temp != cur) { int tempvalue = temp.val; temp.val = cur.val; cur.val = tempvalue; temp = temp.next; } } cur = cur.next; } return head; }}
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
- Servlet之二 —— HttpServlet的doGet()和doPost()
- android thread Handler 、Looper、 Message、 Message Queue
- 过滤器
- 按任意键返回(退出)
- 最最常用的100个Java类
- Insertion Sort List
- Leetcode Best Time to Buy and Sell Stock II
- 线程返回值的方式介绍
- POJ 3304 Segments [判断线段和直线相交]
- VIM插入时间
- 为Ubuntu安装翻译词典(星际译王)
- 【Codeforces】Codeforces Round #271 div2
- 学习篇----数组和指针
- Caused by: Unable to load bean: type: class:com.opensymphony.xwork2.ObjectFactory - bean - jar