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,则深度就可加一,附加判断当前节点是否是叶子节点即可。