###### leetcode Flatten Binary Tree to Linked List树

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.

class Solution {
public:
TreeNode* tail=NULL;//当前指针
void preorder(TreeNode*root)
{
if (root!=NULL)
{
TreeNode*left=root->left;
TreeNode*right = root->right;
if (tail==NULL)//根节点
{
tail = root;
}
else
{
tail->right = root;
tail->left = NULL;
tail = root;
}
preorder(left);
preorder(right);
}
}
void flatten(TreeNode* root) {
if (!root) return;
preorder(root);
}
};

#### Leetcode_114_Flatten Binary Tree to Linked List

2015-01-15 18:40:59

#### 【LeetCode-面试算法经典-Java实现】【114-Flatten Binary Tree to Linked List（二叉树转单链表）】

2015-08-12 06:27:50

#### Leetcode[114]-Flatten Binary Tree to Linked List

2015-06-13 13:01:06

#### LeetCode 114. Flatten Binary Tree to Linked List（摊平二叉树）

2016-05-24 00:19:26

#### 114. Flatten Binary Tree to Linked List（难）

2016-07-25 21:38:12

#### [LeetCode-30]Flatten Binary Tree to Linked List

2014-05-22 04:35:32

#### Flatten Binary Tree to Linked List -- LeetCode

2014-04-15 01:03:20

#### leetcode---Flatten Binary Tree to Linked List

2016-09-24 17:29:32

#### leetcode 114. Flatten Binary Tree to Linked List

2016-04-05 15:26:20

#### leetcode 114.Flatten Binary Tree to Linked List （将二叉树转换链表） 解题思路和方法

2015-08-22 22:35:48

## 不良信息举报

leetcode Flatten Binary Tree to Linked List树