CODE 22: Minimum Depth of Binary Tree
来源:互联网 发布:淘宝0元购在哪里 编辑:程序博客网 时间:2024/05/21 10:01
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.
public int minDepth(TreeNode root) {// Start typing your Java solution below// DO NOT write main() functionif (null == root) {return 0;}Queue<TreeNode> queue = new LinkedList<TreeNode>();queue.offer(root);int layer = 1;int layerNumbers = 1;while (!queue.isEmpty()) {TreeNode node = queue.poll();layerNumbers--;if (null == node.left && null == node.right) {break;}if (null != node.left) {queue.offer(node.left);}if (null != node.right) {queue.offer(node.right);}if (layerNumbers == 0 && !queue.isEmpty()) {layerNumbers = queue.size();layer++;}}return layer;}
- CODE 22: Minimum Depth of Binary Tree
- [leet code] Minimum Depth of Binary Tree
- minimum-depth-of-binary-tree java code
- leetcode 日经贴,Cpp code -Minimum Depth of Binary Tree
- Lee天Code : 111. Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- POJ 3176 Cow Bowling
- 多线程之银行调度系统
- C++类构造函数
- Hadoop DataNode启动之DiskChecker(一)
- android中getSystemService详解
- CODE 22: Minimum Depth of Binary Tree
- Java实验一---模拟ATM
- 增广贤文
- java入门基础------String练习1
- 深入理解C语言----函数调用过程浅析
- QQ通信原理概述
- java入门基础------String练习2
- java入门基础------String练习3
- [各种面试题] 简单表达式计算