POJ - 3974 Palindrome 最长的回文子串 3种不同的方法 字符串hash/Manacher算法

在算法课上,教授提出了一个问题:如何高效找到字符串中最大回文子串的长度?学生们提出的基本思路是检查所有子串,但Andy提出了一种更优的解决方案。他的最终方法包括暴力解法、字符串哈希以及Manacher算法,其中Manacher算法能在O(N)的时间复杂度内解决问题。题目提供了一些测试用例,输入包含多个字符串,以'END'结束,输出每个测试用例的序号和最大回文子串的长度。
摘要由CSDN通过智能技术生成

Andy the smart computer science student was attending an algorithms class when the professor asked the students a simple question, "Can you propose an efficient algorithm to find the length of the largest palindrome in a string?" 

A string is said to be a palindrome if it reads the same both forwards and backwards, for example "madam" is a palindrome while "acm" is not. 

The students recognized that this is a classical problem but couldn't come up with a solution better than iterating over all substrings and checking whether they are palindrome or not, obviously this algorithm is not efficient at all, after a while Andy raised his hand and said "Okay, I've a better algorithm" and before he starts to explain his idea he stopped for a moment and then said "Well, I've an even better algorithm!". 

If you think you know Andy's final solution then prove it! Given a string of at most 1000000 characters find and

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值