Merge pull request #1445 from Gyangle/111_typo_fix

更新 111.二叉树的最小深度 的拼写错误及改进规范
This commit is contained in:
程序员Carl
2022-07-12 08:27:22 +08:00
committed by GitHub

View File

@ -2629,21 +2629,21 @@ JavaScript
var minDepth = function(root) { var minDepth = function(root) {
if (root === null) return 0; if (root === null) return 0;
let queue = [root]; let queue = [root];
let deepth = 0; let depth = 0;
while (queue.length) { while (queue.length) {
let n = queue.length; let n = queue.length;
deepth++; depth++;
for (let i=0; i<n; i++) { for (let i=0; i<n; i++) {
let node = queue.shift(); let node = queue.shift();
// 如果左右节点都是null则该节点深度最小 // 如果左右节点都是null(在遇见的第一个leaf节点上),则该节点深度最小
if (node.left === null && node.right === null) { if (node.left === null && node.right === null) {
return deepth; return depth;
} }
node.left && queue.push(node.left);; node.left && queue.push(node.left);;
node.right && queue.push (node.right); node.right && queue.push(node.right);
} }
} }
return deepth; return depth;
}; };
``` ```