【题目】
Sort a linked list in O(n log n)
time using constant space complexity.
【分析】
单链表适合用归并排序,双向链表适合用快速排序。本题可以复用Merge Two Sorted Lists方法
【代码】
/*********************************
* 日期:2015-01-1...
分类:
其他好文 时间:
2015-01-13 00:10:40
阅读次数:
184
Merge k Sorted ListsMergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.采用优先队列priority_queue把ListNode放入优先队...
分类:
其他好文 时间:
2015-01-12 23:57:44
阅读次数:
266
Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.思路:我自己的,每次找k个元素的最小的接在答案链表的后面。结果超时了。 ListNode *merge...
分类:
其他好文 时间:
2015-01-12 23:44:13
阅读次数:
249
Given an integern, return the number of trailing zeroes inn!.Note:Your solution should be in logarithmic time complexity.Credits:Special thanks to@tsf...
分类:
其他好文 时间:
2015-01-12 22:25:47
阅读次数:
451
Follow up for "Find Minimum in Rotated Sorted Array":
What if duplicates are allowed?
Would this affect the run-time complexity? How and why?
Suppose a sorted array is rotated at some pivot u...
分类:
其他好文 时间:
2015-01-12 21:04:07
阅读次数:
224
Given an integern, return the number of trailing zeroes inn!.Note:Your solution should be in logarithmic time complexity.Credits:Special thanks to@tsf...
分类:
其他好文 时间:
2015-01-12 14:25:06
阅读次数:
126
Given a sorted array of integers, find the starting and ending position of a given target value.
Your algorithm's runtime complexity must be in the order of O(log
n).
If the target is not found in...
分类:
其他好文 时间:
2015-01-12 09:29:25
阅读次数:
119
Given a sorted array of integers, find the starting and ending position of a given target value.
Your algorithm's runtime complexity must be in the order of O(log n).
If the target is not found ...
分类:
其他好文 时间:
2015-01-11 17:51:10
阅读次数:
190
题目:
Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
思路:
我们要计算 N! 中有多少个后导0.
我们来找一下规律,考虑n!的质数因子。后缀0,只有可能是质因子2...
分类:
编程语言 时间:
2015-01-11 16:16:18
阅读次数:
272
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 ...
分类:
其他好文 时间:
2015-01-11 15:59:32
阅读次数:
181