由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - Longest Palindromic Substring from leetcode
相关主题
Leetcode上面这个Longest Palindromic Substring Part II是不是代码有问题?leetcode里的Palindrome partition问题
leetcode上的Longest Palindromic Substring难道不收brute forAmazon Summer Intern Offer, 发面经
请问一道Leetcode的题:Longest Palindromic Substring像Longest Palindromic Substring这种题,面试的时候
leetcode online judge Longest Palindromic Substring memory limit exceeded刚刚结束的Yelp电面面经,顺求bless
Memory Limit Exceeded: Longest Palindromic Substringyelp一题,攒rp
leetcode Longest Palindromic Substring Part II 有问题?Longest Palindromic Substring O(N) 算法
问道算法题有人同看Longest Palindromic Substring 这道题么?
python搞不定Longest Palindromic Substring啊Longest Palindromic Substring 用 vector 超时
相关话题的讨论汇总
话题: radius话题: int话题: extend话题: len话题: maxradius
进入JobHunting版参与讨论
1 (共1页)
F********9
发帖数: 44
1
真无语, 不知道哪里有问题。
目测结果都是对的,比如
"a" "a" "a"
"bb" "bb" "bb"
"ccc" "ccc" "ccc"
我的代码哪里有问题? 希望有高手帮忙:
string longestPalindrome(string s) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int len = s.size();
int *radius = new int[len*2+1];
for (int i=0; i<2*len+1; ++i)
{
radius[i] = 0;
}
char *extend = new char[len*2+2];
for (int i=0, j=0; i {
extend[j+1] = s[i];
extend[j] = '#';
}
extend[len*2] = '#';
extend[len*2+1] = '\0';
int center=0;
int range=0;
for(int i=1; i {
int mirror = center - (i-center);
radius[i] = range >= i ?min(range -i, radius[mirror]):0;
while (extend[i-1-radius[i]] == extend[i+1+radius[i]])
++radius[i];
if(radius[i] + i > range)
{
center = i;
range = i+radius[i];
}
}
int maxcenter=0;
int maxradius=0;
for(int i=0; i {
if(radius[i] > maxradius)
{
maxradius = radius[i];
maxcenter = i;
}
}
delete [] radius;
string ret;
for(int i=maxcenter - maxradius; i {
if(extend[i] != '#')
{
ret.push_back(extend[i]);
}
}
delete[] extend;
return ret;
}
1 (共1页)
进入JobHunting版参与讨论
相关主题
Longest Palindromic Substring 用 vector 超时 Memory Limit Exceeded: Longest Palindromic Substring
求问一道面试题 ciscoleetcode Longest Palindromic Substring Part II 有问题?
问问 leetcode 新题问道算法题
LeetCode LongestValidParenthesespython搞不定Longest Palindromic Substring啊
Leetcode上面这个Longest Palindromic Substring Part II是不是代码有问题?leetcode里的Palindrome partition问题
leetcode上的Longest Palindromic Substring难道不收brute forAmazon Summer Intern Offer, 发面经
请问一道Leetcode的题:Longest Palindromic Substring像Longest Palindromic Substring这种题,面试的时候
leetcode online judge Longest Palindromic Substring memory limit exceeded刚刚结束的Yelp电面面经,顺求bless
相关话题的讨论汇总
话题: radius话题: int话题: extend话题: len话题: maxradius