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,
1
/ \
2 3
/ \ \
4 5 7
After calling your function, the tree should look like:
1 -> NULL
/ \
2 -> 3 -> NULL
/ \ \
4 -> 5 -> 7 -> NULL
问题描述:给定一个二叉树,使每个节点的next指针指向它的右边的节点,和之前的Populating Next Right Pointers in Each Node类似,只是这次的二叉树不是完全二叉树,但是方法和思想与之前的一样。
本文探讨了如何在任意二叉树中填充每个节点的next指针,使其指向右侧相邻节点。该问题是对“Populating Next Right Pointers in Each Node”的扩展,要求在常数额外空间条件下完成。
456

被折叠的 条评论
为什么被折叠?



