注意题目中所说的是从跟节点到叶节点的最短距离
/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public int minDepth(TreeNode root){
if(null == root) return 0;
else if(null == root.left && null == root.right) return 1;
else if(null == root.left) return minDepth(root.right) + 1;
else if(null == root.right) return minDepth(root.left) + 1;
else return Math.min(minDepth(root.left), minDepth(root.right)) + 1;
}
}