题目链接: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)).
这...
分类:
其他好文 时间:
2015-01-27 23:34:01
阅读次数:
169
题目:Sort a linked list in O(n log n)
time using constant space complexity.
思路:题目要求我们使用常数空间复杂度,时间复杂度为O(nlog(n)). 满足这个时间复杂度的有快速排序,归并排序,堆排序。插入排序时间复杂度为O(n^2). 双向链表用快排比较合适,堆排序也可用于链表,单项链表适合于归并排序。我们就用归并排序的...
分类:
编程语言 时间:
2015-01-27 11:13:51
阅读次数:
190
Sort a linked list inO(nlogn) time using constant space complexity.常见排序方法有很多,插入排序,选择排序,堆排序,快速排序,冒泡排序,归并排序,桶排序等等。。它们的时间复杂度不尽相同,而这里题目限定了时间必须为O(nlgn),符合要...
分类:
编程语言 时间:
2015-01-26 13:23:44
阅读次数:
194
Given an integern, return the number of trailing zeroes inn!.Note:Your solution should be in logarithmic time complexity.public class Solution { pu...
分类:
其他好文 时间:
2015-01-25 20:55:19
阅读次数:
119
Search for a RangeGiven a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity ...
分类:
其他好文 时间:
2015-01-24 15:46:00
阅读次数:
107
【题目】
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...
分类:
其他好文 时间:
2015-01-24 13:11:16
阅读次数:
163
‘算法空间复杂度’,别以为这个东西多么高大上,我保证你看完这篇文章就能明白。最近在啃算法,发现非常有趣。在我学习的过程中发现了一个问题,那就是空间复杂度的问题,它绝对是效率的杀手。关于空间复杂度的介绍(摘自百度)空间复杂度(Space Complexity)是对一个算法在运行过程中临时占用存储空间大...
分类:
编程语言 时间:
2015-01-23 12:55:28
阅读次数:
195
‘算法空间复杂度’,别以为这个东西多么高大上,我保证你看完这篇文章就能明白。最近在啃算法,发现非常有趣。在我学习的过程中发现了一个问题,那就是空间复杂度的问题,它绝对是效率的杀手。关于空间复杂度的介绍(摘自百度)空间复杂度(Space Complexity)是对一个算法在运行过程中临时占用存储空间大...
分类:
编程语言 时间:
2015-01-23 12:46:34
阅读次数:
114
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...
分类:
其他好文 时间:
2015-01-22 01:40:55
阅读次数:
130
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-21 21:58:16
阅读次数:
273