fix: 修改第111题二叉树最小深度js代码

This commit is contained in:
coderwei
2022-07-05 15:36:27 +08:00
parent 26ad08fe50
commit b982b79830

View File

@ -372,7 +372,7 @@ var minDepth1 = function(root) {
// 到叶子节点 返回 1
if(!root.left && !root.right) return 1;
// 只有右节点时 递归右节点
if(!root.left) return 1 + minDepth(root.right);
if(!root.left) return 1 + minDepth(root.right);
// 只有左节点时 递归左节点
if(!root.right) return 1 + minDepth(root.left);
return Math.min(minDepth(root.left), minDepth(root.right)) + 1;