Merge pull request #1509 from coderwei99/master

fix: 修改第111题二叉树最小深度js代码
This commit is contained in:
程序员Carl
2022-08-01 10:57:34 +08:00
committed by GitHub

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;