Skip to content

Commit 3652d00

Browse files
authored
0104 二叉树最大深度 部分代码书写错误纠正
函数错误,逻辑错误
1 parent 1810a9a commit 3652d00

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

problems/0104.二叉树的最大深度.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,8 @@ func maxdepth(root *treenode) int {
523523

524524
```javascript
525525
var maxdepth = function(root) {
526-
if (!root) return root
527-
return 1 + math.max(maxdepth(root.left), maxdepth(root.right))
526+
if (root === null) return 0;
527+
return 1 + Math.max(maxdepth(root.left), maxdepth(root.right))
528528
};
529529
```
530530

@@ -541,7 +541,7 @@ var maxdepth = function(root) {
541541
//3. 确定单层逻辑
542542
let leftdepth=getdepth(node.left);
543543
let rightdepth=getdepth(node.right);
544-
let depth=1+math.max(leftdepth,rightdepth);
544+
let depth=1+Math.max(leftdepth,rightdepth);
545545
return depth;
546546
}
547547
return getdepth(root);
@@ -591,7 +591,9 @@ var maxDepth = function(root) {
591591
count++
592592
while(size--) {
593593
let node = queue.shift()
594-
node && (queue = [...queue, ...node.children])
594+
for (let item of node.children) {
595+
item && queue.push(item);
596+
}
595597
}
596598
}
597599
return count

0 commit comments

Comments
 (0)