Код: Выделить всё
class Solution:
def longestPalindrome(self, s: str, checked = set()) -> str:
print(s, self.isPalindrome(s))
if len(s) == 1 or self.isPalindrome(s):
return s
if s in checked:
print(s, checked)
return s[0] #shortest palindrome in s
checked.add(s)
lp2 = self.longestPalindrome(s[:-1], checked)
lp1 = self.longestPalindrome(s[1:], checked)
print()
if len(lp1) > len(lp2):
return lp1
return lp2
def isPalindrome(self, s:str) -> str:
i=0
j=len(s)-1
while i
Подробнее здесь: [url]https://stackoverflow.com/questions/78704895/oobabooga-leetcode-question-longest-palindromic-substring-solution-works-in-cus[/url]