LeetCode第5题:Longest Palindromic Substring总结

题目:

Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.

  • 大意:就是找出字符串中最大的回文子字符串

吐槽:

这应该是一道经典的算法题,可是我还是没有什么好办法,可见我真的是太菜了。哎。。。用了一个O( n^2 )的解法,妥妥的超时了。。。后来看了网上的有关文章和discuss里面的代码,修改了版本。

暴力超时版Python代码:

(肯定是我自己写的)

Python(修正版)


参考:

最长回文字符串》http://www.cnblogs.com/houkai/p/3371807.html

Accepted 4ms c++ solution.》https://leetcode.com/discuss/40559/accepted-4ms-c-solution

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注