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代码: (肯定是我自己写的) class Solution(object): def longestPalindrome(self, s): longest_str = “” longest_len = 0 for i in range(len(s) – 1): […]