Optimized O(N) -> O(1) for a __contains__ check inside linked_list/has_loop.py#4287
Optimized O(N) -> O(1) for a __contains__ check inside linked_list/has_loop.py#4287yoreei wants to merge 6 commits intoTheAlgorithms:masterfrom
Conversation
|
I think your comment in line 17 needs one more space before the #-sign if I read the error message correctly. |
|
@algobytewise You are right. I also accidentally pushed a separate PR into this one. I'll revert that and make it PEP8 conformant. |
|
What would be supercool is to have both approaches in a single file with a |
|
@cclauss That's a great idea. Thanks for bringing it up. |
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
Please reopen this pull request once you commit the changes requested or make improvements on the code. If this is not the case and you need some help, feel free to seek help from our Gitter or ping one of the reviewers. Thank you for your contributions! |
Describe your change:
data_structures/linked_list/has_loop.py: class Node: iter:
Previous implementation used lists for keeping track of visited nodes. The corrected version uses sets. See
https://wiki.python.org/moin/TimeComplexity
Checklist:
Fixes: #{$ISSUE_NO}.