Maximum GapGiven an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/spac...
分类:
其他好文 时间:
2014-12-14 11:52:36
阅读次数:
136
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...
分类:
其他好文 时间:
2014-12-14 10:46:23
阅读次数:
189
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.解题思路:找到链表的中点,作为根,前端作为左子树,后端作为右子树,并对前后做递归操...
分类:
其他好文 时间:
2014-12-13 13:21:52
阅读次数:
153
Catalogue: array-分治法搜索
Question
Suppose a sorted array is rotated at some pivot unknown to you beforehand.
(i.e., 0 1 2 4 5 6 7 might become 4
5 6 7 0 1 2).
Find the minimum element.
...
分类:
其他好文 时间:
2014-12-13 09:38:26
阅读次数:
139
Catalogue:array - 分治法
Question
Suppose a sorted array is rotated at some pivot unknown to you beforehand.
(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).
Find the minimum element.
The array may...
分类:
其他好文 时间:
2014-12-13 09:37:25
阅读次数:
157
Given a sorted integer array where the range of elements are [lower, upper] inclusive, return its missing ranges.For example, given [0, 1, 3, 50, 75],...
分类:
其他好文 时间:
2014-12-13 06:07:01
阅读次数:
223
题目
Merge k sorted linked lists and return it
as one sorted list. Analyze and describe its complexity.
解答
方法1:利用分治的思想把合并k个链表分成两个合并k/2个链表的任务,一直划分,知道任务中只剩一个链表或者两个链表。可以很简单的用递归来实现。因此算法复杂度为T(k) =
2...
分类:
其他好文 时间:
2014-12-12 19:15:28
阅读次数:
120
题目
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.
解答
题目要求将链表转化为二叉查找树。利用树的中序遍历的递归思想,对链表结点一个个进行访问,先对左子树进行递归,然后将当前结点作为根,迭代到下一个链表结点,最后在递...
分类:
其他好文 时间:
2014-12-12 19:04:40
阅读次数:
127
Remove Duplicates from Sorted ArrayGiven a sorted array, remove the duplicates in place such that each element appear onlyonceand return the new lengt...
分类:
其他好文 时间:
2014-12-12 11:29:06
阅读次数:
166
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(log (k)), k = mi...
分类:
其他好文 时间:
2014-12-11 15:53:14
阅读次数:
193