Minimum Window SubstringGiven 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).Fo...
原题:
Given an array of integers, every element appears three times except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it withou...
分类:
其他好文 时间:
2014-08-15 14:46:48
阅读次数:
207
原题:
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.
思路:两条两条地合并。时间复杂度为O(n),n为所有链表节点和。
代码:
/**
* Definition for singly-linked list.
* struct List...
分类:
其他好文 时间:
2014-08-14 20:52:09
阅读次数:
275
Problem Description:
Sort a linked list in O(n log n)
time using constant space complexity.
分析:对链表进行排序,思考排序算法时间复杂度为O(nlogn)的只有归并,快排和堆排序,应用到链表上的归并比较合适,这里利用快慢指针找到链表的中间节点,然后分别对两边递归归并排好序后将两边归并即可得到最终...
分类:
其他好文 时间:
2014-08-13 22:25:57
阅读次数:
234
Problem:
Sort a linked list in O(n log n)
time using constant space complexity.
解题思路:
首先,时间复杂度能达到O(nlgn)的排序算法,常见的有3种:堆排序、归并排序和快速排序,
而对于链表,用堆排序显然不太可能,所以,我们可用归并或者是快排.由于合并...
分类:
其他好文 时间:
2014-08-12 00:45:13
阅读次数:
217
Time, Delays, and Deferred Work
Dealing with time involves the following tasks, in order of increasing complexity:
? Measuring time lapses and comparing times
? Knowing the cur...
分类:
其他好文 时间:
2014-08-12 00:41:13
阅读次数:
484
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)).
public class Solution {
...
分类:
其他好文 时间:
2014-08-11 15:14:12
阅读次数:
188
O(n) complexity, have a traversal for the tree. Get the information of all children, then traverse the tree again.
#include
#include
#include
#include
using namespace std;
class Node {
pub...
分类:
其他好文 时间:
2014-08-10 13:00:30
阅读次数:
238
Sort a linked list in O(n log n) time using constant space complexity.思路:题目要求O(n log n)的时间复杂度以及常空间复杂度,因此,使用归并排序策略。 1 class Solution { 2 public: 3 ...
分类:
其他好文 时间:
2014-08-09 23:13:19
阅读次数:
284
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 ...
分类:
其他好文 时间:
2014-08-09 18:18:28
阅读次数:
214