![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Leet Code -- Sort
lili616
这个作者很懒,什么都没留下…
展开
-
【Leet Code】148. Sort List---Medium
Sort a linkedlist in O(n log n) time using constant space complexity. 思路: 借助2-路归并排序实现。 基本思想: 归并排序(Merging Sort)法是将两个(或两个以上)有序表合并成一个新的有序表,即把待排序序列分为若干个子序列,每个子序列是有序的。然后再把有序子序列合并为整体有序序列。 时间复杂度:O(nl原创 2015-09-15 16:13:00 · 359 阅读 · 0 评论 -
【Leet Code】147. Insertion Sort List---Medium
Sort a linkedlist using insertion sort. 思路: 插入排序主要有直接插入排序和希尔插入排序, 1) 直接插入排序 把一个记录插入到一个已经排好序的有序表中,从而得到一个新的,记录数增1的有序表。 时间复杂度: O(n^2), 空间复杂度:O(1)。稳定排序算法。 图示: 2)希尔排序,又称“缩小增量排序”。 先将整个待排记录序列分割成若干原创 2015-09-15 16:08:25 · 330 阅读 · 0 评论 -
【Leet Code】 242. Valid Anagram--easy
Given twostrings s and t, write a function to determine if t isan anagram of s. For example, s = "anagram", t = "nagaram", return true. s = "rat", t = "car", return false. Note: You may assume th原创 2015-09-15 16:04:50 · 297 阅读 · 0 评论 -
【Leet Code】54. Spiral Matrix---Medium
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. For example, Given the following matrix: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]原创 2015-11-05 10:35:37 · 285 阅读 · 0 评论 -
【Leet Code】 75.Sort Colors--medium
Given anarray with n objects colored red, white or blue, sort them so thatobjects of the same color are adjacent, with the colors in the order red, whiteand blue. Here, we will use the integers 0, 1,原创 2015-09-15 16:06:40 · 311 阅读 · 0 评论 -
【Leet Code】59. Spiral Matrix II---Medium
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For example, Given n = 3, You should return the following matrix: [ [ 1, 2, 3 ], [ 8, 9, 4 ], [原创 2015-11-05 11:18:12 · 260 阅读 · 0 评论 -
【Leet Code】56. Merge Intervals---Hard
Given a collection of intervals, merge all overlapping intervals. For example, Given [1,3],[2,6],[8,10],[15,18], return [1,6],[8,10],[15,18]. 思路: 刚看到这个题目没看懂什么意思,先对题目进行说明: 对以两个数对为元素的数组(原创 2015-10-29 11:47:10 · 259 阅读 · 0 评论 -
【Leet Code】274. H-Index---Medium
Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index. According to the definition of h-index on Wikipedia: "A原创 2015-10-29 10:46:17 · 348 阅读 · 0 评论 -
【Leet Code】164. Maximum Gap---Hard
Given an unsorted array, find the maximum difference between the successive elements in its sorted form. Try to solve it in linear time/space. Return 0 if the array contains less than 2 elements原创 2015-11-02 15:49:54 · 392 阅读 · 0 评论