Open
Conversation
kyra-patton
reviewed
Jul 26, 2022
kyra-patton
left a comment
There was a problem hiding this comment.
✨ Nice work, Maria. I left some style suggestions, but it looks like you have a good grasp on linked lists. Let me know what questions you have.
🟢
| # Space Complexity: ? | ||
| # Time Complexity: O(1) | ||
| # Space Complexity: O(1) | ||
| def get_first(self): |
| # Space Complexity: ? | ||
| # Time Complexity: O(1) | ||
| # Space Complexity: O(1) | ||
| def add_first(self, value): |
| # Space Complexity: ? | ||
| # Time Complexity: O(n) | ||
| # Space Complexity: O(1) | ||
| def search(self, value): |
Comment on lines
+64
to
+69
| if current_node.next: | ||
| current_node = current_node.next | ||
| else: | ||
| return length | ||
| else: | ||
| return length |
There was a problem hiding this comment.
🤓 Style suggestion to condense your code. Since your while condition is essentially to check if current_node is a Node object or None, just set current_node to current_node.next regardless of whether next is a Node or None.
If it's None, your while loop will finish executing and you can just return whatever length is at that point!
Suggested change
| if current_node.next: | |
| current_node = current_node.next | |
| else: | |
| return length | |
| else: | |
| return length | |
| current_node = current_node.next | |
| return length | |
| # Space Complexity: ? | ||
| # Time Complexity: O(n) | ||
| # Space Complexity: O(1) | ||
| def get_at_index(self, index): |
| # Space Complexity: ? | ||
| # Time Complexity: O(n) | ||
| # Space Complexity: O(1) | ||
| def add_last(self, value): |
| # returns the data value and not the node | ||
| # Time Complexity: O(n) | ||
| # Space Complexity: O(1) | ||
| def find_max(self): |
| # Space Complexity: ? | ||
| # Time Complexity: O(n) | ||
| # Space Complexity: O(1) | ||
| def reverse(self): |
| # Space Complexity: ? | ||
| # Time Complexity: O(n) | ||
| # Space Complexity: O(n) | ||
| def visit(self): |
Comment on lines
+147
to
+149
| if current_node.value == value: | ||
| self.head = current_node.next | ||
| break |
There was a problem hiding this comment.
🤓I would suggest using return over break statements
Suggested change
| if current_node.value == value: | |
| self.head = current_node.next | |
| break | |
| if current_node.value == value: | |
| self.head = current_node.next | |
| return | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.