【leetcode】148. Sort List】的更多相关文章

作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.com/problems/sort-list/description/ 题目描述 Sort a linked list in O(n log n) time using constant space complexity. Example 1: Input: 4->2->1->3 Output…
Sort a linked list in O(n log n) time using constant space complexity. 链表排序可以用很多方法,插入,冒泡,选择都可以,也容易实现,但是复杂度不符合题意要求. 然后时间复杂度在O(nlogn)的排序算法中,堆排序,快速排序,归并排序. 堆排序,主要是基于数组的,这里是链表,实现起来比较麻烦. 快速排序,快速排序最坏情况的时间复杂度是O(n2) 归并排序,在对数组的归并排序中,是有O(n)的空间复杂度的,但是链表可以不需要,我们…
题目如下: 解题思路:本题和[leetcode]75. Sort Colors类似,但是没有要求在输入数组本身修改,所以难度降低了.引入一个新的数组,然后遍历输入数组,如果数组元素是是偶数,插入到新数组头部,否则追加到尾部. 代码如下: class Solution(object): def sortArrayByParity(self, A): """ :type A: List[int] :rtype: List[int] """ res =…
链接:https://leetcode.com/tag/sort/ [56]Merge Intervals (2019年1月26日,谷歌tag复习) 合并区间 Input: [[1,3],[2,6],[8,10],[15,18]] Output: [[1,6],[8,10],[15,18]] Explanation: Since intervals [1,3] and [2,6] overlaps, merge them into [1,6]. 题解:先按照interval的begin从小到大s…
Sort List Sort a linked list in O(n log n) time using constant space complexity. Example 1: Input: 4->2->1->3 Output: 1->2->3->4 Example 2: Input: -1->5->3->4->0 Output: -1->0->3->4->5 解法1 归并排序.用两个函数实现: merge:将两个有…
Sort Colors Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue. Here, we will use the integers 0, 1, and 2 to represent the color red, w…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 库函数排序 桶排序 红黑树排序 归并排序 快速排序 日期 题目地址:https://leetcode.com/problems/sort-an-array/ 题目描述 Given an array of integers nums, sort the array in ascending order. Example 1: Input: [5,2,3…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 使用奇偶数组 排序 奇偶数位置变量 日期 题目地址: https://leetcode.com/problems/sort-array-by-parity-ii 题目描述 Given an array A of non-negative integers, half of the integers in A are odd, and half of…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 计数排序 双指针 日期 题目地址:https://leetcode.com/problems/sort-colors/description/ 题目描述 Given an array with n objects colored red, white or blue, sort them so that objects of the same col…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典 优先级队列 排序 日期 题目地址:https://leetcode.com/problems/sort-characters-by-frequency/description/ 题目描述 Given a string, sort it in decreasing order based on the frequency of character…