将二叉树转化为链表。
114. Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place.
For example,
Given
1 |
1 |
The flattened tree should look like:
1 |
1 |
Hints:
If you notice carefully in the flattened tree, each node’s right child points to the next node of a pre-order traversal.
算法:利用二叉树前序遍历算法的递归实现求解
1 |
public TreeNode preNode = null; |
近期评论