Question: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.
//给一颗二叉树,求从根节点到叶子节点的最小距离
思路:树的遍历 一般有广度优先遍历和深度优先遍历
广度优先搜索算法(Breadth First Search),又叫宽度优先搜索,或横向优先搜索。广度优先遍历的非递归的通用做法是采用队列。
代码原型如下:
void breadthFirstSearch(Tree root){
queue
minimum-depth-of-binary-tree
最新推荐文章于 2020-06-01 09:24:40 发布