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 {
523523
524524``` javascript
525525var 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
You can’t perform that action at this time.
0 commit comments