问题描述: Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example 1: Example 2: 思路: 根据 ...
分类:
其他好文 时间:
2018-05-26 10:44:49
阅读次数:
162
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. Your algorithm should run in O(n) complexity. Examp ...
分类:
其他好文 时间:
2018-05-23 13:07:29
阅读次数:
303
Recursion: 时间O(n) 空间O(h) 因为要找最长的连续路径,我们在遍历树的时候需要两个信息,一是目前连起来的路径有多长,二是目前路径的上一个节点的值。我们通过递归把这些信息代入,然后通过返回值返回一个最大的就行了。 ...
分类:
其他好文 时间:
2018-05-23 11:57:56
阅读次数:
163
Description Given an undirected weighted graph G, you should find one of spanning trees specified as follows. The graph G is an ordered pair (V, E), w ...
分类:
其他好文 时间:
2018-05-23 00:11:33
阅读次数:
206
class Solution { public: int longestConsecutive(vector& nums) { unordered_set s(nums.begin(), nums.end()); int res = 0; while (!s.empty()) { int p = *... ...
分类:
其他好文 时间:
2018-05-20 15:33:11
阅读次数:
151
Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string "". Exampl ...
分类:
编程语言 时间:
2018-05-19 17:02:12
阅读次数:
177
[抄题]: [暴力解法]: 时间分析: 空间分析: [优化后]: 时间分析: 空间分析: [奇葩输出条件]: [奇葩corner case]: [思维问题]: 不知道为什么len[i] == len[j] + 1:因为可以间隔相加。 也不知道为什么是DP:原来小人是间隔着跳的。 [一句话思路]: [ ...
分类:
其他好文 时间:
2018-05-16 00:45:37
阅读次数:
169
描述 The D-pairs of a string of letters are the ordered pairs of letters that are distance D from each other. A string is D-unique if all of its D-pairs ...
分类:
其他好文 时间:
2018-05-14 13:19:15
阅读次数:
186
题目描述 对于两个字符串,请设计一个时间复杂度为O(m*n)的算法(这里的m和n为两串的长度),求出两串的最长公共子串的长度。这里的最长公共子串的定义为两个序列U1,U2,..Un和V1,V2,...Vn,其中Ui + 1 == Ui+1,Vi + 1 == Vi+1,同时Ui == Vi。 给定两 ...
分类:
其他好文 时间:
2018-05-12 16:49:41
阅读次数:
175
题目链接:http://acm.fzu.edu.cn/problem.php?pid=2216 题意:给你n张纸牌,代表的数字在1至m区间,给出k张joker可以充当任何牌,现在求出最大的连续区间的长度。 题目分析:枚举连续序列的起点,二分枚举二分序列的终点 ...
分类:
其他好文 时间:
2018-05-10 23:30:40
阅读次数:
234