File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -523,8 +523,8 @@ func maxdepth(root *treenode) int {
523
523
524
524
``` javascript
525
525
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 ))
528
528
};
529
529
```
530
530
@@ -541,7 +541,7 @@ var maxdepth = function(root) {
541
541
// 3. 确定单层逻辑
542
542
let leftdepth= getdepth (node .left );
543
543
let rightdepth= getdepth (node .right );
544
- let depth= 1 + math .max (leftdepth,rightdepth);
544
+ let depth= 1 + Math .max (leftdepth,rightdepth);
545
545
return depth;
546
546
}
547
547
return getdepth (root);
@@ -591,7 +591,9 @@ var maxDepth = function(root) {
591
591
count++
592
592
while (size-- ) {
593
593
let node = queue .shift ()
594
- node && (queue = [... queue, ... node .children ])
594
+ for (let item of node .children ) {
595
+ item && queue .push (item);
596
+ }
595
597
}
596
598
}
597
599
return count
You can’t perform that action at this time.
0 commit comments