Skip to content
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

chapter 4--tree-- question 4 solution added to the bottom #224

Conversation

shirinyamani
Copy link
Contributor

Hi, thanks for your great work!
I have added my solution which I found easier to understand at the bottom of your code under the Alternative Recursive Approach comment! Hope this helps the community and people getting ready for the interviews!

Copy link
Collaborator

@brycedrennan brycedrennan left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution! I've left feedback just for educational purposes.

I made some small changes and merged your work here: c35c99b

#Alternative Recursive Approach

# Balanced Tree
class Node():
Copy link
Collaborator

Choose a reason for hiding this comment

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

This class isn't used in the code anywhere and can thus be deleted.

self.right = right


def helper(root):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is too generic of a function name. Names should describe what the function does. In this case, _find_height would be a good name.


return max(leftheight, rightheight) + 1

def isBalanced(root):
Copy link
Collaborator

Choose a reason for hiding this comment

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

function names in python should use underscore case (is_balanced)

HOD101s pushed a commit to HOD101s/CtCI-6th-Edition-Python-1 that referenced this pull request May 3, 2022
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