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