Merge pull request #1088 from Jerry-306/master

0059  螺旋矩阵II  题目错误纠正
This commit is contained in:
程序员Carl
2022-03-02 09:52:39 +08:00
committed by GitHub
3 changed files with 8 additions and 6 deletions

View File

@ -10,7 +10,7 @@
[力扣题目链接](https://leetcode-cn.com/problems/spiral-matrix-ii/) [力扣题目链接](https://leetcode-cn.com/problems/spiral-matrix-ii/)
给定一个正整数 n生成一个包含 1 到 $n^2$ 所有元素,且元素按顺时针顺序螺旋排列的正方形矩阵。 给定一个正整数 n生成一个包含 1 到 n^2 所有元素且元素按顺时针顺序螺旋排列的正方形矩阵。
示例: 示例:

View File

@ -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

View File

@ -19,7 +19,7 @@
**首先要注意是判断左叶子,不是二叉树左侧节点,所以不要上来想着层序遍历。** **首先要注意是判断左叶子,不是二叉树左侧节点,所以不要上来想着层序遍历。**
因为题目中其实没有说清楚左叶子究竟是什么节点,那么我来给出左叶子的明确定义:**如果左节点不为空,且左节点没有左右孩子,那么这个节点就是左叶子** 因为题目中其实没有说清楚左叶子究竟是什么节点,那么我来给出左叶子的明确定义:**如果左节点不为空,且左节点没有左右孩子,那么这个节点的左节点就是左叶子**
大家思考一下如下图中二叉树,左叶子之和究竟是多少? 大家思考一下如下图中二叉树,左叶子之和究竟是多少?