# 111. 二叉树的最小深度（***）

给定一个二叉树，找出其最小深度。

3
/ \
9  20
/  \
15   7

class Solution {
public int minDepth(TreeNode root) {
if(root == null)
return 0;

int leftH  = minDepth(root.left);
int rightH  = minDepth(root.right);

if(leftH == 0 || rightH == 0)
return leftH + rightH + 1;
else
return Math.min(leftH,rightH) + 1;
}
}
class Solution {
public int minDepth(TreeNode root) {
if(root == null)
return 0;
int leftH = 0;
if(root.left != null)
leftH = minDepth(root.left);
int rightH = 0;
if(root.right != null)
rightH = minDepth(root.right);

if(leftH == 0)
return rightH + 1;
else if(rightH == 0)
return leftH + 1;
else
return Math.min(leftH,rightH) + 1;
}
}

class Solution {
public int minDepth(TreeNode root) {
if(root == null)
return 0;
int res = 1;
TreeNode nlast = null;
TreeNode last = root;
queue.offer(root);
nlast = root;
while(!queue.isEmpty()){
TreeNode cur = queue.poll();
if(cur.left == null && cur.right == null )
return res;

if(cur.left != null){
queue.offer(cur.left);
nlast = cur.left;
}
if(cur.right != null){
queue.offer(cur.right);
nlast = cur.right;
}
if(cur == last){
last = nlast;
res++;
}
}
return res;
}
}