37. Populating Next Right Pointers

You are given a perfect binary tree: every parent has two children and all leaves are on the same level. Write a function Node Connect(Node root) that fills Next pointers so each node points to its right neighbor on the same level (or NULL if none). Initially all Next values are NULL. Return the tree root.
Example 1
Input: root = [1]
Output: [1,#]
Explanation:
Example 2
Input: root = []
Output: []
Explanation:
Example 3
Input: root = [1,2,3,4,5,6,7]
Output: [1,#,2,3,#,4,5,6,7,#]
Explanation:
mediumtree
JavaScript
Loading...
Line 1, Char 1