We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ee7a3bc commit 7084335Copy full SHA for 7084335
go/0116-populating-next-right-pointers-in-each-node.go
@@ -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
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