-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rock - Hannah L. #43
base: master
Are you sure you want to change the base?
Rock - Hannah L. #43
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is why some tests are failing.
elif key <= current_node: | |
elif key <= current_node.key: |
# Time Complexity: O(log n) | ||
# Space Complexity: O(1) | ||
def find(self, key): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
# Time Complexity: O(n) | ||
# Space Complexity: O(n) | ||
def inorder(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
# Time Complexity: O(n) | ||
# Space Complexity: O(n) | ||
def preorder(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
# Time Complexity: O(n) | ||
# Space Complexity: O(n) | ||
def postorder(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also do this with the max
function
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) |
No description provided.