题目:Follow up for "Search in Rotated Sorted Array":What ifduplicatesare allowed?Would this affect the run-time complexity? How and why?Write a function...
分类:
其他好文 时间:
2014-07-07 00:14:37
阅读次数:
186
Sort a linked list in O(n log n) time using constant space complexity.merge sort、heap sort和quick sort都是O(nlgn),但是mergesort和quicksort都是递归的,不是constant s...
分类:
其他好文 时间:
2014-07-06 21:07:41
阅读次数:
210
Given an array of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complexity...
分类:
其他好文 时间:
2014-07-06 13:17:57
阅读次数:
199
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)).
有两个已排序的数组A和B,大小为m 和 n。
找出两数组的中...
分类:
其他好文 时间:
2014-07-05 22:54:17
阅读次数:
244
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 ord...
分类:
其他好文 时间:
2014-07-05 19:10:48
阅读次数:
219
Follow up for "Search in Rotated Sorted Array":What ifduplicatesare allowed?Would this affect the run-time complexity? How and why?Write a function to...
分类:
其他好文 时间:
2014-07-03 21:59:51
阅读次数:
199
Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.合并k个排序列表解题思路是:取出 k个元素进行堆排序,每次取出最小的元素,插入链表中即可注意本题利用了c++...
分类:
其他好文 时间:
2014-07-02 20:16:54
阅读次数:
273
【题目】
Sort a linked list in O(n log n) time using constant space complexity.
【题意】
排序一个链表,要求时间复杂度O(nlogn),使用常量空间
【思路】
nlogn的复杂度,用归并排序求解...
分类:
其他好文 时间:
2014-07-02 09:25:40
阅读次数:
252
Sort a linked list in O(n log n)
time using constant space complexity.
看到O(n log n)的排序算法,适合单链表的首先想到的就是归并排序
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* Lis...
分类:
其他好文 时间:
2014-07-02 08:47:34
阅读次数:
239
题目
Given an array of integers, every element appears twice except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it witho...
分类:
其他好文 时间:
2014-07-01 06:24:42
阅读次数:
204