1
/* Definition for a Node.
2
* function Node(val, left, right, next) {
3
* this.val = val === undefined ? null : val;
4
* this.left = left === undefined ? null : left;
5
* this.right = right === undefined ? null : right;
6
* this.next = next === undefined ? null : next;
7
* };
8
*/
9

10
/**
11
* @param {Node} root
12
* @return {Node}
13
*/
14
var connect = function (root) {
15
if (!root || !root.left || !root.right) {
16
return root;
17
}
18

19
root.left.next = root.right;
20
if (root.next) {
21
root.right.next = root.next.left;
22
} else {
23
root.right.next = null;
24
}
25

26
root.left = connect(root.left);
27
root.right = connect(root.right);
28

29
return root;
30
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0