Given an integern, return the number of trailing zeroes inn!.Note:Your solution should be in logarithmic time complexity.解析: 只有2和5相乘才会出现0,其中整十也可以看做是2和...
分类:
其他好文 时间:
2015-03-17 19:47:19
阅读次数:
136
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-03-17 17:29:47
阅读次数:
156
Sort a linked list in O(n log n) time using constant space complexity.
这道题是要求对单链表进行排序,有个O(nlogn)的时间复杂度的要求。我的想法是采取类似头插法的方式,遍历链表结点,设3个指针,min指向当前链表中的最小值,max指向当前链表中的最大值,cur指向前一插入的值。
min , max , cur 初始时都指向第...
分类:
其他好文 时间:
2015-03-17 15:58:02
阅读次数:
181
Given an array of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complexity...
分类:
其他好文 时间:
2015-03-17 02:00:44
阅读次数:
102
题目:Sort a linked list in O(n log n) time using constant space complexity.
思路:要求时间复杂度O(nlogn)
知识点:归并排序,链表找到中点的方法
存在的缺点:边界条件多考虑!!!
/**
* LeetCode Sort List Sort a linked list in O(n log n) time us...
分类:
编程语言 时间:
2015-03-16 23:14:12
阅读次数:
260
problem:
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)).
thinking:
(1)求中位数,就是求已...
分类:
其他好文 时间:
2015-03-16 21:26:18
阅读次数:
162
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S="ADOBECODEBA...
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-03-15 12:13:53
阅读次数:
112
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-03-14 21:40:42
阅读次数:
134
Merge k Sorted Lists问题:Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.思路: 归并排序(二分问题)我的代码:public clas....
分类:
其他好文 时间:
2015-03-13 10:45:10
阅读次数:
120