https://leetcode.com/problems/minimum-depth-of-binary-tree/description/
111. Minimum Depth of Binary Tree
给你一个二元树,返回他的最小深度,最小深度为 root 节点到叶子节点的最小距离。
Example 1:
https://assets.leetcode.com/uploads/2020/10/12/ex_depth.jpg
Input: root = [3,9,20,null,null,15,7]
Output: 2
Example 2:
Input: root = [2,null,3,null,4,null,5,null,6]
Output: 5
思路:
1.用广度优先去traversal二元树,如果某个节点的左右两个子节点都为空,表示找到
最小深度。
Java Code: