文章 2023-01-05 来自:开发者社区

LeetCode 148. Sort List

DescriptionSort a linked list in O(n log n) time using constant space complexity.Example 1:Input: 4->2->1->3Output: 1->2->3->4Example 2:Input: -1->5->3->4->0Output: -1-&a...

LeetCode 148. Sort List
文章 2017-12-04 来自:开发者社区

[LeetCode] Sort List 链表排序

Sort a linked list in O(n log n) time using constant space complexity. 常见排序方法有很多,插入排序,选择排序,堆排序,快速排序,冒泡排序,归并排序,桶排序等等。。它们的时间复杂度不尽相同,而这里题目限定了时间必须为O(nlgn),符合要求只有快速排序,归并排序,堆排序,而根据单链表的特点,最适于用...

文章 2015-06-29 来自:开发者社区

[LeetCode] Insertion Sort List

Well, life gets difficult pretty soon whenever the same operation on array is transferred to linked list. First, a quick recap of insertion sort: Start from the second element (simply a[1] i...

文章 2015-06-02 来自:开发者社区

[LeetCode] Sort List

There are many merge-sort solutions at the forum, but very few quicksort solutions. So I post my accepted quicksort solution here. Well, after reading the problem statement, I intuitively select quic....

文章 2015-02-16 来自:开发者社区

[LeetCode] Insertion Sort List

Sort a linked list using insertion sort. 解题思路 对于得到结点current的插入位置,从头结点开始遍历,直到遍历到值大于等于节点current的结点,然后将从该结点到current的前驱结点的所有结点的值依次和current结点的值交换,从而达到将该节点插入所遍历到的位置的目的。 实现代码 /**************************...

文章 2015-02-15 来自:开发者社区

[LeetCode] Sort List

Sort a linked list in O(n log n) time using constant space complexity. 解题思路 可以利用归并排序解决该问题。普通的归并排序算法时间复杂度为O(nlogn),空间复杂度为O(n),因为需要建立两个数组来存储原来数组的值,这两个数组的长度加起来恰好为原数组的长度。但是对于链表可以省去复制两个已经排好序的数组的操作,从而使空...

文章 2015-01-09 来自:开发者社区

[LeetCode]147.Insertion Sort List

【题目】 Sort a linked list using insertion sort. 【分析】 无 【代码】 /********************************* * 日期:2015-01-09 * 作者:SJF0115 * 题目: 147.Insertion Sort List * 来源:https://oj.leetcode.com/problems/...

文章 2014-11-09 来自:开发者社区

[LeetCode 第7题] -- Sort List

题目链接: Sort List 题目意思: 给定一个链表头结点,在O(nlogn)时间内进行排序 分析: 比较排序下限是O(nlogn),可以选择归并排序解决(事实证明,快速排序会TLE) 代码: /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *ne...

文章 2014-11-08 来自:开发者社区

[LeetCode 第6题] -- Insertion Sort List

题目链接: Insertion Sort List 题目意思: 利用插入排序,对链表排序 代码: /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} ...

本页面内关键词为智能算法引擎基于机器学习所生成,如有任何问题,可在页面下方点击"联系我们"与我们沟通。

算法编程

开发者社区在线编程频道官方技术圈。包含算法资源更新,周赛动态,每日一题互动。

+关注