103. Populating Next Right Pointers in Each Node
MediumTree
You are given a perfect binary tree where all leaves are on the same level, and every parent has two children. Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL. Initially, all next pointers are set to NULL.
Examples
Input: [1,2,3,4,5,6,7]
Output: [1,#,2,3,#,4,5,6,7,#]
Explanation: Each node points to its right neighbor at the same level.
Constraints
- The number of nodes in the tree is in the range [0, 2^12 - 1].
- -1000 <= Node.val <= 1000
Loading...
Run checks all cases above. Submit evaluates all test cases.