二叉树的最大深度
var maxDepth = function(root) {
return !root ? 0 : Math.max(maxDepth(root.left),maxDepth(root.right)) + 1
};
二叉树的最小深度
var minDepth = function(root) {
if(!root){
return 0
}
if(!root.left){
return minDepth(root.right)+1
}
if(!root.right){
return minDepth(root.left)+1
}
return Math.min(minDepth(root.left),minDepth(root.right))+1
};