You are given a perfect binary tree (all leaves are at the same level and every parent has exactly two children).
Set each node’s next pointer to point to the node on its right in the same level.
If there is no node to the right, set next to NULL.
Input: root = [10,5,15,3,7,12,18]
Output: [10,#,5,15,#,3,7,12,18,#]
Explanation:
Each node’s next pointer connects to the node immediately on its right within the same level. # marks the end of a level.
Input: root = []
Output: []
Explanation:
The tree is empty, so there are no connections.
Accepted:
Submission: