Skip to content

Latest commit

 

History

History
18 lines (9 loc) · 777 Bytes

File metadata and controls

18 lines (9 loc) · 777 Bytes

二叉树的最小深度(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.

给定一个二叉树,找出其最小的深度。最小的深度指的是从根节点到距离其最近的叶子节点之间路径中的节点数。

解题思路

利用层序遍历的思想,数据结构采用队列,从第一层开始在每一层的最后一个节点入队之后再多入一个null,标记当前层已经结束,这样每当出队的元素为null,则深度就可加一,附加判断当前节点是否是叶子节点即可。

代码

这里