mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 20:40:39 +08:00
0104 二叉树最大深度 部分代码书写错误纠正
函数错误,逻辑错误
This commit is contained in:
@ -523,8 +523,8 @@ func maxdepth(root *treenode) int {
|
|||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var maxdepth = function(root) {
|
var maxdepth = function(root) {
|
||||||
if (!root) return root
|
if (root === null) return 0;
|
||||||
return 1 + math.max(maxdepth(root.left), maxdepth(root.right))
|
return 1 + Math.max(maxdepth(root.left), maxdepth(root.right))
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -541,7 +541,7 @@ var maxdepth = function(root) {
|
|||||||
//3. 确定单层逻辑
|
//3. 确定单层逻辑
|
||||||
let leftdepth=getdepth(node.left);
|
let leftdepth=getdepth(node.left);
|
||||||
let rightdepth=getdepth(node.right);
|
let rightdepth=getdepth(node.right);
|
||||||
let depth=1+math.max(leftdepth,rightdepth);
|
let depth=1+Math.max(leftdepth,rightdepth);
|
||||||
return depth;
|
return depth;
|
||||||
}
|
}
|
||||||
return getdepth(root);
|
return getdepth(root);
|
||||||
@ -591,7 +591,9 @@ var maxDepth = function(root) {
|
|||||||
count++
|
count++
|
||||||
while(size--) {
|
while(size--) {
|
||||||
let node = queue.shift()
|
let node = queue.shift()
|
||||||
node && (queue = [...queue, ...node.children])
|
for (let item of node.children) {
|
||||||
|
item && queue.push(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return count
|
return count
|
||||||
|
Reference in New Issue
Block a user