leetcode_shadow

@leetcode_shadow

Posts made by leetcode_shadow

my solution is a force one,testing the substring by different length for len(s) to 1.BUT always TLE at "aaaa…aaaa", i think for this case my method is O(n) ,and i tried to avoid the "aaaa….aaaa" case:

if s.startswith("aaaa") :
return s

And, got the same result . Anyone knows the reason? thx~~

class Solution:
# @return a string
def longestPalindrome(self, s):
i = length = len(s)
for i in range(i,1,-1): # i is the length for the current testing substring
for j in range(0,length-i+1): # j is the start point of the substring
pos_start = start = j
pos_end = end = j + i - 1
while start <= end :
if s[start] == s[end]:
start += 1
end -= 1
else:
break
if start > end :
if i == length: # just to avoid creating a new substring
return s
else:
new_str = s[pos_start:pos_end+1]
return new_str