Skip to content

Instantly share code, notes, and snippets.

@wenweixu
Last active November 11, 2020 09:30
Show Gist options
  • Save wenweixu/e36177c44f8841de6774946eab4a9302 to your computer and use it in GitHub Desktop.
Save wenweixu/e36177c44f8841de6774946eab4a9302 to your computer and use it in GitHub Desktop.
Hackerrank Height of a Binary Tree Python solution
def height(root):
# condition to stop recursion
if root == None:
return -1
# divide and conquer
depth_left = height(root.left)
depth_right = height(root.right)
depth = max(depth_left, depth_right) + 1
# return the final result
return depth
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment