Skip to content

Instantly share code, notes, and snippets.

@liondancer
Created January 5, 2017 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liondancer/ea75bd7b84ac7c16400d11945270cf98 to your computer and use it in GitHub Desktop.
Save liondancer/ea75bd7b84ac7c16400d11945270cf98 to your computer and use it in GitHub Desktop.
def minDepth(root):
"""
:type root: TreeNode
:rtype: int
"""
if root is None:
return 0
elif root.left is None:
return minDepth(root.right) + 1
elif root.right is None:
return minDepth(root.left) + 1
else:
return min(minDepth(root.left), minDepth(root.right)) + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment