题目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 = “ADOBECODEBANC”
T = “ABC”
Minimum window is “BANC”.Note...
Given a strings, partitionssuch that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning ofs...
分类:
其他好文 时间:
2015-02-24 13:43:16
阅读次数:
150
二分搜索,和LeetCode 153. Find Minimum in Rotated Sorted Array相似。
只是在num[begin] == num[mid]时,需要binary_search(++ begin, end, num); 这时仅将begin移进一位,并没有进行二分查找。
所以如测试用例为 num = {1, 1, 1, 1, 1, ..., 1}等特殊情况时,最坏情况...
分类:
其他好文 时间:
2015-02-24 00:50:43
阅读次数:
206
Problem DescriptionThe inversion number of a given number sequence a1, a2, …, an is the number of pairs (ai, aj) that satisfy i aj.For a given sequence of numbers a1, a2, …, an, if we move...
分类:
其他好文 时间:
2015-02-23 23:44:23
阅读次数:
400
二分查找。
因为在旋转前的数组是排好序了的,
所以当num[begin] > num[mid]时,表示我们要搜寻的最小数字在num[begin, ..., mid]之间;
反之,num[begin]
例:考虑num = {5, 6, 7, 1, 2, 3, 4},
begin = 0, end = 6, mid = 3
num[begin] = 5 > num[m...
分类:
其他好文 时间:
2015-02-23 23:43:09
阅读次数:
350
动态规划。
dp[0][i]: A[0, ..., i-1]的maximum product subarray,
dp[1][i]: A[0, ..., i-1)的minimum product subarray.
初始化dp[0][0] = dp[1][0] = A[0].
递推公式:
dp[0][i] = max(dp[0][i-1]*A[i], dp[1][i-1]*A[i])...
分类:
其他好文 时间:
2015-02-23 20:08:09
阅读次数:
163
Given a connected undirected graph, tell if its minimum spanning tree is unique.
Definition 1 (Spanning Tree): Consider a connected, undirected graph G = (V, E). A spanning tree of G is a subgraph of G, say T = (V', E'), with the following properties:
1...
分类:
其他好文 时间:
2015-02-23 15:33:46
阅读次数:
257
Given an integer array, adjust each integers so that the difference of every adjcent integers are not greater than a given number target.If the array ...
分类:
其他好文 时间:
2015-02-23 15:26:38
阅读次数:
115
范围最小值问题(Range Minimum Query)
给出一个n个元素的数组,设计数据结构使得支持查询操作Query(L,R) 计算[L,R]中最小值
Tarjan的Sparse-Table算法预处理时间为O(nlogn) 查询只需要O(1)而且常数很小。假设dp[i][j]表示从第i个数开始的2^j个数的最小值。
有下列公式:dp[i][j] = min(dp[i,j-1],dp[i+2...
分类:
编程语言 时间:
2015-02-22 21:57:56
阅读次数:
200
Minimum SumTime Limit: 16000/8000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2667Accepted Submission(s): 609Problem...
分类:
其他好文 时间:
2015-02-22 20:44:41
阅读次数:
207