Ad
  • Custom User Avatar

    Hi, I have a question about finding the length of the longest substring in the given string s that is the same in reverse. As an example, if the input was “I like racecars that go fast”, the substring (racecar) length would be 7. My code is follow and I don't know where is wrong, How do I do this?

    def longest_palindrome (s):
    for i in range(len(s)):
    for j in range(len(s),i,-1):
    n = s[i:j]
    if n == n[::-1]:
    return len(n)