Skip to content

Instantly share code, notes, and snippets.

@evidanary
Last active October 24, 2017 07:09
Show Gist options
  • Save evidanary/2eeb325aabb4900a2d634941f826348a to your computer and use it in GitHub Desktop.
Save evidanary/2eeb325aabb4900a2d634941f826348a to your computer and use it in GitHub Desktop.
# returns depth and node at the maximum depth
def max_depth(node)
return [0, node] if node.nil?
left = max_depth(node.left) + 1
right = max_depth(node.right) + 1
left[0] > right[0] ? left : right
ends
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment