From 5ee2f42edb5765f6e28f2022fbcd257f27914b06 Mon Sep 17 00:00:00 2001 From: qiufeihong2018 <15058301288@163.com> Date: Mon, 29 Apr 2024 16:12:38 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=200102.=E4=BA=8C=E5=8F=89=E6=A0=91?= =?UTF-8?q?=E7=9A=84=E5=B1=82=E5=BA=8F=E9=81=8D=E5=8E=86.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0102.二叉树的层序遍历.md | 40 ++++++++++++----------- problems/图论深搜理论基础.md | 2 +- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/problems/0102.二叉树的层序遍历.md b/problems/0102.二叉树的层序遍历.md index 4411b560..d834eef7 100644 --- a/problems/0102.二叉树的层序遍历.md +++ b/problems/0102.二叉树的层序遍历.md @@ -692,27 +692,29 @@ func levelOrderBottom(root *TreeNode) [][]int { #### Javascript: ```javascript -var levelOrderBottom = function(root) { - let res = [], queue = []; - queue.push(root); - while(queue.length && root!==null) { - // 存放当前层级节点数组 - let curLevel = []; - // 计算当前层级节点数量 - let length = queue.length; - while(length--) { - let node = queue.shift(); - // 把当前层节点存入curLevel数组 - curLevel.push(node.val); - // 把下一层级的左右节点存入queue队列 - node.left && queue.push(node.left); - node.right && queue.push(node.right); - } - // 从数组前头插入值,避免最后反转数组,减少运算时间 - res.unshift(curLevel); +var levelOrderBottom = function (root) { + let res = [], + queue = []; + queue.push(root); + while (queue.length && root !== null) { + // 存放当前层级节点数组 + let curLevel = []; + // 计算当前层级节点数量 + let length = queue.length; + while (length--) { + let node = queue.shift(); + // 把当前层节点存入curLevel数组 + curLevel.push(node.val); + // 把下一层级的左右节点存入queue队列 + node.left && queue.push(node.left); + node.right && queue.push(node.right); } - return res; + // 从数组前头插入值,避免最后反转数组,减少运算时间 + res.unshift(curLevel); + } + return res; }; + ``` #### TypeScript: diff --git a/problems/图论深搜理论基础.md b/problems/图论深搜理论基础.md index 7f847f8f..15c5af3a 100644 --- a/problems/图论深搜理论基础.md +++ b/problems/图论深搜理论基础.md @@ -71,7 +71,7 @@ 有递归的地方就有回溯,那么回溯在哪里呢? -就地递归函数的下面,例如如下代码: +就递归函数的下面,例如如下代码: ```cpp void dfs(参数) {