diff --git a/0111-minimum-depth-of-binary-tree/0111-minimum-depth-of-binary-tree.py b/0111-minimum-depth-of-binary-tree/0111-minimum-depth-of-binary-tree.py new file mode 100644 index 0000000..2a1199e --- /dev/null +++ b/0111-minimum-depth-of-binary-tree/0111-minimum-depth-of-binary-tree.py @@ -0,0 +1,20 @@ +# Definition for a binary tree node. +# class TreeNode(object): +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution(object): + def minDepth(self, root): + """ + :type root: TreeNode + :rtype: int + """ + if not root: + return 0 + if not root.left: + return 1 + self.minDepth(root.right) + if not root.right: + return 1 + self.minDepth(root.left) + return 1 + min(self.minDepth(root.left), self.minDepth(root.right)) +