Skip to content

Lesson7 - #8

Open
iisat wants to merge 4 commits into
lesson7from
lesson8
Open

iisat wants to merge 4 commits into
lesson7from
lesson8

Conversation

@iisat

@iisat iisat commented Nov 24, 2018

Copy link
Copy Markdown
Owner

No description provided.

@Dzhoker1 Dzhoker1 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread Lesson8/task1.py
hashesarray = []
for i in range(0, len(s)):
for j in range(0, len(s)):
if hash(s[i:j + 1]) not in hashesarray:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread Lesson8/task1.py
def mod_count_substrings(s):
d = collections.OrderedDict()
for i in range(0, len(s)):
for j in range(0, len(s)):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread Lesson8/task1.py

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

Copy link
Copy Markdown

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.

2 participants