Код: Выделить всё
def longest_palindrome(s):
return s == s[::-1]
def find_palindromes_bruteforce(input_word):
palindromes = []
n = len(input_word)
for i in range(n):
for j in range(i + 1, n):
if longest_palindrome(input_word[i:j + 1]):
palindromes.append(input_word[i:j + 1])
return palindromes
s = "babad"
print(longest_palindrome(s))
Код: Выделить всё
/usr/local/bin/python3.12 /Users/jaredmccarthy/Desktop/2025/ejercicios_leetcode.py
False
Process finished with exit code 0
Код: Выделить всё
longest_palindrome(word)Код: Выделить всё
s = "babad"Подробнее здесь: https://stackoverflow.com/questions/797 ... st-palindr
Мобильная версия