Leetcode 111 Minimum Depth of Binary Tree

Given a binary tree, find its minimum depth.

The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.

def min_depth(root)

    return 0 if not root

    return min_depth(root.left) + 1 if not root.right

    return min_depth(root.right) + 1 if not root.left

    [min_depth(root.right), min_depth(root.left)].min + 1

end

 

你可能感兴趣的:(LeetCode)