avatar
d*w
1
应该是老题了,http://www.careercup.com/question?id=245679 讨论了半天,
比如这种:
1. Original string is A
2. Reverse string is B
3. Find common strings are C, D, E ....
4. Find palindromic strings in step 3, suppose C, D.
5. Find the max length of strings in step 4. Return.
有人说是错的,
到底那种正确又简洁的方法呢,请大牛指点
avatar
i*9
2
我觉得是对的,有人认为是错的是觉得(find longest common substring of A and B,
自动认为是longest palindromic不对)
avatar
l*a
3
你这个复杂度是多少?
有一种O(N2)很直接的
string is a[0]..a[n-1],
assume a[i] (i=1..n-2) is the middle(or a[i+1])
judge whether a[i+k]==a[i-k] then k++ or get the
longest palindrome with center a[i]...
最快的是generalized suffix tree,O(N),but need extra space
store A and reverse string B in the GST,
for(i=1;ifind max LCA(a[i],b[n-1-i])and LCA(a[i],b[n-i])

【在 d********w 的大作中提到】
: 应该是老题了,http://www.careercup.com/question?id=245679 讨论了半天,
: 比如这种:
: 1. Original string is A
: 2. Reverse string is B
: 3. Find common strings are C, D, E ....
: 4. Find palindromic strings in step 3, suppose C, D.
: 5. Find the max length of strings in step 4. Return.
: 有人说是错的,
: 到底那种正确又简洁的方法呢,请大牛指点

avatar
c*e
4
suffix tree o(n)
avatar
f*4
5
为啥不对?想不通

B,

【在 i**9 的大作中提到】
: 我觉得是对的,有人认为是错的是觉得(find longest common substring of A and B,
: 自动认为是longest palindromic不对)

avatar
f*4
6
面试时候会让你写如何build一个后缀树的代码么。。。。我脚着我是肯定写不出的。
。。

【在 c******e 的大作中提到】
: suffix tree o(n)
avatar
l*a
7
还得写个O(n)建树的。

【在 f*******4 的大作中提到】
: 面试时候会让你写如何build一个后缀树的代码么。。。。我脚着我是肯定写不出的。
: 。。

avatar
l*a
8
其实建树好写
关键是make sure that it support O(1) LCA algorithm【 在 forever84 (to be
with you) 的大作中提到: 】
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。