Created
January 5, 2017 01:58
-
-
Save liondancer/ea75bd7b84ac7c16400d11945270cf98 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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