Skip to content

Conversation

@iisat
Copy link
Owner

@iisat iisat commented Nov 24, 2018

No description provided.

Copy link

@Dzhoker1 Dzhoker1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Оставил комментарии по коду

hashesarray = []
for i in range(0, len(s)):
for j in range(0, len(s)):
if hash(s[i:j + 1]) not in hashesarray:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Каждая проверка наличия хэша в списке имеет сложность O(n), отсюда и такой разрыв во времени выполнения.

def mod_count_substrings(s):
d = collections.OrderedDict()
for i in range(0, len(s)):
for j in range(0, len(s)):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Второй цикл можно начинать не от 0, а от j.


# Проверяем работу функции
print(count_substrings('mama'))
print(count_substrings('mama'))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Отличное решение

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants