Skip to content

Commit

Permalink
LC-0116
Browse files Browse the repository at this point in the history
Signed-off-by: Tahsin Tunan <[email protected]>
  • Loading branch information
tahsintunan committed Dec 28, 2022
1 parent ee7a3bc commit 7084335
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions go/0116-populating-next-right-pointers-in-each-node.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Definition for a Node.
* type Node struct {
* Val int
* Left *Node
* Right *Node
* Next *Node
* }
*/

func connect(root *Node) *Node {
populate(root)
return root
}

func populate(node *Node) {
if node == nil {
return
}
if node.Left == nil {
return
}

node.Left.Next = node.Right
if node.Next != nil {
node.Right.Next = node.Next.Left
}
populate(node.Left)
populate(node.Right)
}

0 comments on commit 7084335

Please sign in to comment.