mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 02:53:31 +08:00
Merge pull request #1445 from Gyangle/111_typo_fix
更新 111.二叉树的最小深度 的拼写错误及改进规范
This commit is contained in:
@ -2629,21 +2629,21 @@ JavaScript:
|
||||
var minDepth = function(root) {
|
||||
if (root === null) return 0;
|
||||
let queue = [root];
|
||||
let deepth = 0;
|
||||
let depth = 0;
|
||||
while (queue.length) {
|
||||
let n = queue.length;
|
||||
deepth++;
|
||||
depth++;
|
||||
for (let i=0; i<n; i++) {
|
||||
let node = queue.shift();
|
||||
// 如果左右节点都是null,则该节点深度最小
|
||||
// 如果左右节点都是null(在遇见的第一个leaf节点上),则该节点深度最小
|
||||
if (node.left === null && node.right === null) {
|
||||
return deepth;
|
||||
return depth;
|
||||
}
|
||||
node.left && queue.push(node.left);;
|
||||
node.right && queue.push(node.right);
|
||||
}
|
||||
}
|
||||
return deepth;
|
||||
return depth;
|
||||
};
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user