Skip to content

Latest commit

 

History

History
44 lines (27 loc) · 1.1 KB

0111-minimum-depth-of-binary-tree.adoc

File metadata and controls

44 lines (27 loc) · 1.1 KB

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.

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]