TGViewer
PythonBoost - сообщество питонистов PythonBoost - сообщество питонистов @pythonboost · 10.8K subscribers
Post #1261 2.32K
Ответ к предыдущей задаче для новичков.

def longest_substring(s):
n = len(s)
substrings = set()
max_substring = None
max_count = 0
for i in range(n):
for j in range(i + 1, n + 1):
substr = s[i:j]
if substr in substrings:
count = s.count(substr)
if count > max_count:
max_substring = substr
max_count = count
elif count == max_count and len(substr) > len(max_substring):
max_substring = substr
else:
substrings.add(substr)
return (max_substring, max_count)

#pythonзадача #coбес
  • 👍 1
More from @pythonboost
  1. Aug 25, 2026Статья дня. Функция any() в Python Часто в программах на Python требуется проверить, являе…
  2. Aug 25, 2026🔍Тестовое собеседование на Middle Python с разработчиком из Яндекса завтра вечером Уже за…
  3. Aug 25, 2026photo post
  4. Aug 25, 2026Как найти все четные числа в списке за одну строку кода? evens = [x for x in [1, 2, 3, 4,…
  5. Aug 5, 2026Видео дня. Решаем задачи на Python с Codewars Продолжаем покорять Codewars. Решаем популяр…
  6. Aug 4, 2026photo post
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →