Skip to content

Commit 801cc98

Browse files
authored
Update 116-populating-next-right-pointers-in-each-node.js
1 parent e7e8b3c commit 801cc98

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

116-populating-next-right-pointers-in-each-node.js

+13
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,16 @@ const connect = function(root) {
2727
}
2828
return root
2929
}
30+
31+
// another
32+
33+
const connect = function(root) {
34+
if (!root) return null
35+
if (root.left && root.right) {
36+
root.left.next = root.right
37+
root.right.next = root.next ? root.next.left : null
38+
}
39+
connect(root.left)
40+
connect(root.right)
41+
return root
42+
}

0 commit comments

Comments
 (0)