From 44019c84ab0e583d55714472ae6f5131b77a6286 Mon Sep 17 00:00:00 2001 From: Jerry-306 <82520819+Jerry-306@users.noreply.github.com> Date: Sat, 25 Sep 2021 20:23:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=200116=20=E5=A1=AB=E5=86=99?= =?UTF-8?q?=E6=AF=8F=E4=B8=80=E4=B8=AA=E8=8A=82=E7=82=B9=E5=8F=91=E4=B8=8B?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E5=8F=B3=E4=BE=A7=E6=8C=87=E9=92=88=20JavaSc?= =?UTF-8?q?ript=E7=89=88=E6=9C=AC=20=E8=A7=A3=E6=B3=95=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增 0116 填写每一个节点发下一个右侧指针 JavaScript版本 解法代码 --- problems/0102.二叉树的层序遍历.md | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/problems/0102.二叉树的层序遍历.md b/problems/0102.二叉树的层序遍历.md index 5128d6ec..79d3547d 100644 --- a/problems/0102.二叉树的层序遍历.md +++ b/problems/0102.二叉树的层序遍历.md @@ -1263,7 +1263,41 @@ class Solution: first = first.left # 从本层扩展到下一层 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 root; + let queue = [root]; + while (queue.length) { + let n = queue.length; + for (let i=0; i