Given a binary tree, flatten it to a linked list in-place.
For example,
Given
1
/ \
2 5
/ \ \
3 4 6
The flattened tree should look like:
1
\
2
\
3
\
4
\
5
\
6
Hints:
If you notice carefully in the flattened tree, each node's right child points to the next node of a pre-order traversal.
本文介绍了如何使用递归和栈实现将二叉树转换为链表的操作,确保每一步操作都清晰明了,特别强调了在处理每个节点时将左子节点设置为null的小技巧。
846

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



