- 40ms
- 81%
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def minDepth(self, root: TreeNode) -> int:
if not root: return 0
d = (self.minDepth(root.left), self.minDepth(root.right))
return 1+(min(d) or max(d))