题目: Sort a linked list inO(nlogn) time using
constant space complexity.解题思路: 复杂度为O(n* logn)
的排序算法有:快速排序、堆排序、归并排序。对于链表这种数据结构,使用归并排序比较靠谱。递归代码如下:代码: /...
分类:
其他好文 时间:
2014-05-16 05:49:04
阅读次数:
266
leetCode-002 Median of Two Sorted Arrays
【题目】
There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).
【题意】
有两个有序的数组,找出这两数组整合后的中位数,要求时间复杂度O(nlogn)...
分类:
其他好文 时间:
2014-05-15 04:42:05
阅读次数:
274
Mergeksorted linked lists and return it as one
sorted list. Analyze and describe its
complexity.思路:合并k个有序链表为一个有序链表。我们可以用先合并两个链表的方法,然后逐个遍历链表数组,与上一个合并结束...
分类:
其他好文 时间:
2014-05-12 15:07:06
阅读次数:
305
There are two sorted arrays A and B of size m
and n respectively. Find the median of the two sorted arrays. The overall run
time complexity should be ...
分类:
其他好文 时间:
2014-05-09 23:26:18
阅读次数:
353
Mergeksorted linked lists and return it as one
sorted list. Analyze and describe its complexity.想法很简单,就是两两合并。在Merge Two Sorted
Lists这道题已经实现了两两合并的代码了,就...
分类:
其他好文 时间:
2014-05-06 00:22:01
阅读次数:
337
Merge k Sorted Lists
Total Accepted: 9746 Total
Submissions: 41674My Submissions
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity....
分类:
其他好文 时间:
2014-05-01 17:11:32
阅读次数:
234
题目: There are two sorted arrays A and B of size m
and n respectively. Find the median of the two sorted arrays. The overall run
time complexity should...
分类:
其他好文 时间:
2014-04-29 10:32:46
阅读次数:
359