← 返回 linkedin 的题目列表Populating Next Right Pointers in Each Node
类型:online_judge
Given a perfect binary tree, 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.
Input Format:
The input is the root node of a perfect binary tree Node, where the height h ranges from [1, 12].
Output Format:
Modify the tree in-place, you do not need to return anything.
Constraints:
You must use constant extra space. Recursive calls are allowed on the stack as extra space.
Example:
Input: A perfect binary tree with level order traversal [1, 2, 3, 4, 5, 6, 7]
Output: The modified tree with each node's next right pointer as illustrated in the diagram
Constraints:
The tree is a perfect binary tree, meaning all parent nodes have two children and all leaf nodes are at the same level.
Example
Input
1
2
3
4
5
6
7