Tree
117. Populating Next Right Pointers in Each Node II
1. Question
Follow up for problem "Populating Next Right Pointers in Each Node".
What if the given tree could be any binary tree? Would your previous solution still work?
Note:
You may only use constant extra space.
For example, Given the following binary tree,
After calling your function, the tree should look like:
2. Implementation
(1) BFS
(2) Iteration
3. Time & Space Complexity
BFS: 时间复杂度: O(n), 空间复杂度: O(w), w是树中拥有最多node的一层中的node个数
Iteration: 时间复杂度: O(n), 空间复杂度: O(1)
Last updated
Was this helpful?