Open
Conversation
CheezItMan
reviewed
Dec 4, 2021
CheezItMan
left a comment
There was a problem hiding this comment.
Overall nice work Hannah, one typo preventing the tests from passing, but otherwise nice work.
| def add_helper(self, current_node, key, value): | ||
| if current_node == None: | ||
| return TreeNode(key, value) | ||
| elif key <= current_node: |
There was a problem hiding this comment.
This is why some tests are failing.
Suggested change
| elif key <= current_node: | |
| elif key <= current_node.key: |
Comment on lines
+33
to
35
| # Time Complexity: O(log n) | ||
| # Space Complexity: O(1) | ||
| def find(self, key): |
Comment on lines
+59
to
61
| # Time Complexity: O(n) | ||
| # Space Complexity: O(n) | ||
| def inorder(self): |
Comment on lines
+84
to
86
| # Time Complexity: O(n) | ||
| # Space Complexity: O(n) | ||
| def preorder(self): |
Comment on lines
+102
to
104
| # Time Complexity: O(n) | ||
| # Space Complexity: O(n) | ||
| def postorder(self): |
Comment on lines
+117
to
+124
| left_height = 1 + self.max_height_helper(root.left, height) | ||
| right_height = 1 + self.max_height_helper(root.right, height) | ||
|
|
||
| # compare to find max | ||
| if left_height < right_height: | ||
| return right_height | ||
| else: | ||
| return left_height |
There was a problem hiding this comment.
You can also do this with the max function
Suggested change
| left_height = 1 + self.max_height_helper(root.left, height) | |
| right_height = 1 + self.max_height_helper(root.right, height) | |
| # compare to find max | |
| if left_height < right_height: | |
| return right_height | |
| else: | |
| return left_height | |
| left_height = 1 + self.max_height_helper(root.left, height) | |
| right_height = 1 + self.max_height_helper(root.right, height) | |
| return max(right_height, left_height) |
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.