您的位置:首页 > 其它

Leetcode 111, Minimum Depth of Binary Tree

2016-10-23 07:40 489 查看
public int minDepth(TreeNode root) {
if(root == null)
return 0;
int left = minDepth(root.left);
int right = minDepth(root.right);
if(root.left == null){
return right + 1;
}else if(root.right == null){
return left + 1;
}
return Math.min(left, right) + 1;
}

refer: http://blog.csdn.net/linhuanmars/article/details/19660209
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: