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 class Solution {
public int run(TreeNode root) {
return getDepth(root,0);
}
public static int getDepth(TreeNode node,int height){
if(node==null){
return height;
}
if(node.left==null){
return getDepth(node.right,height+1);
}
if(node.right==null){
return getDepth(node.left,height+1);
}
return Math.min(getDepth(node.left,height+1),getDepth(node.right,height+1));
}
}