From 5eabb4ff9b2c887c8194cc6cb46d3d96a706084b Mon Sep 17 00:00:00 2001 From: Jerry-306 <82520819+Jerry-306@users.noreply.github.com> Date: Sat, 25 Sep 2021 20:34:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20117=E9=A2=98=E3=80=81104?= =?UTF-8?q?=E9=A2=98=E3=80=81111=E9=A2=98=E7=AD=89=20JavaScript=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增 117.填充每个节点的下一个右侧节点指针II JavaScript版本解法代码 新增 104二叉树最大深度 JavaScript版本解法代码 新增 111.二叉树的最小深度 JavaScript版本解法代码 --- problems/0102.二叉树的层序遍历.md | 97 ++++++++++++++++++++++- 1 file changed, 95 insertions(+), 2 deletions(-) diff --git a/problems/0102.二叉树的层序遍历.md b/problems/0102.二叉树的层序遍历.md index 5128d6ec..330a4f62 100644 --- a/problems/0102.二叉树的层序遍历.md +++ b/problems/0102.二叉树的层序遍历.md @@ -1426,7 +1426,39 @@ class Solution: first = dummyHead.next # 此处为换行操作,更新到下一行 return root ``` +JavaScript: +```javascript +/** + * // Definition for a Node. + * function Node(val, left, right, next) { + * this.val = val === undefined ? null : val; + * this.left = left === undefined ? null : left; + * this.right = right === undefined ? null : right; + * this.next = next === undefined ? null : next; + * }; + */ +/** + * @param {Node} root + * @return {Node} + */ +var connect = function(root) { + if (root === null) { + return null; + } + let queue = [root]; + while (queue.length > 0) { + let n = queue.length; + for (let i=0; i