Skip to content

Commit 7084335

Browse files
committed
LC-0116
Signed-off-by: Tahsin Tunan <[email protected]>
1 parent ee7a3bc commit 7084335

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Definition for a Node.
3+
* type Node struct {
4+
* Val int
5+
* Left *Node
6+
* Right *Node
7+
* Next *Node
8+
* }
9+
*/
10+
11+
func connect(root *Node) *Node {
12+
populate(root)
13+
return root
14+
}
15+
16+
func populate(node *Node) {
17+
if node == nil {
18+
return
19+
}
20+
if node.Left == nil {
21+
return
22+
}
23+
24+
node.Left.Next = node.Right
25+
if node.Next != nil {
26+
node.Right.Next = node.Next.Left
27+
}
28+
populate(node.Left)
29+
populate(node.Right)
30+
}

0 commit comments

Comments
 (0)