昨天做了leetcode里的 Longest Palindromic Substring ,一开始用动态规划O(N^2),不管怎么改都超时了。。。于是在大神的帮助下,找到了传说中的Manacher算法,居然能在O(n)内求出来,瞬间给跪了。
本屌认为,这个算法主要是充分的利用了以前的匹配的结果,来起到了降低时间复杂度的作用,这点跟KMP算是有点类似。在预处理时有个小技巧就是将第0,1为设...
分类:
其他好文 时间:
2014-06-20 12:15:22
阅读次数:
305
原题地址:https://oj.leetcode.com/problems/longest-consecutive-sequence/题意:Given
an unsorted array of integers, find the length of the longest consecutive ...
分类:
编程语言 时间:
2014-06-06 23:13:20
阅读次数:
324
Given a binary tree, find its maximum depth.The
maximum depth is the number of nodes along the longest path from the root node
down to the farthest le...
分类:
其他好文 时间:
2014-06-05 14:10:38
阅读次数:
304
Longest Valid Parentheses 最长有效括号对...
分类:
其他好文 时间:
2014-06-05 01:16:14
阅读次数:
215
title:
The following iterative sequence is defined for the set of positive integers:
n
n/2 (n is even)
n 3n + 1 (n is odd)
Using the rule above and starting with 13, we generate the followi...
分类:
其他好文 时间:
2014-06-04 13:56:33
阅读次数:
254
求最长合法匹配的长度,这道题可以用一维动态规划逆向求解。假设输入括号表达式为String s,维护一个长度为s.length的一维数组dp[],数组元素初始化为0。 dp[i]表示从s[i]到s[s.length - 1]包含s[i]的最长的有效匹配括号子串长度。则存在如下关系:...
分类:
其他好文 时间:
2014-06-04 13:52:03
阅读次数:
279
1、Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
clas...
分类:
其他好文 时间:
2014-06-02 23:13:22
阅读次数:
290
Given a stringS, find the longest palindromic
substring inS. You may assume that the maximum length ofSis 1000, and there
exists one unique longest pa...
分类:
编程语言 时间:
2014-06-02 09:22:03
阅读次数:
328
题目:
给定一个字符串,返回该串没有重复字符的最长子串。
分析:
1)子串:子串要求是连续的。
2)无重复,出现重复就断了,必须从新的位置开始。而新的位置就是重复字符第一次出现位置的下一个位置。
3)整个串可能没有一处重复。
那么,为了找出当前访问的字符是否出现过,要怎么做呢?当然是hash,O(1)的时间,而且既然是字符, 定义个255的hash table 就可以了,has...
分类:
其他好文 时间:
2014-06-01 10:48:31
阅读次数:
206