{leetcode}/problems/minimum-depth-of-binary-tree/[LeetCode - 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.
Note: A leaf is a node with no children.
Example:
Given binary tree [3,9,20,null,null,15,7]
,
3 / \ 9 20 / \ 15 7
return its minimum depth = 2.
使用深度优先搜索和广度优先搜索来解决这个问题。
link:{sourcedir}/_0111_MinimumDepthOfBinaryTree.java[role=include]
Tip
|
可以换个角度理解这道题:使用 Morris 遍历树时,遍历到每个节点时,计算该节点的深度,然后从中筛选出叶子阶段的深度,取最小值即可。 |
link:{sourcedir}/_0111_MinimumDepthOfBinaryTree_Morris.java[role=include]
竟然在 LeetCode 中文站点没有找到使用 Morris 遍历方法处理的解答。