标签:
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
class Solution { public: TreeNode *node = NULL; void flatten(TreeNode *root) { if(root == NULL) return; if(node != NULL) { node->left = NULL; node->right = root; } node = root; TreeNode *left = root->left; TreeNode *right = root->right; flatten(left); flatten(right); } };
Flatten Binary Tree to Linked List
标签:
原文地址:http://blog.csdn.net/uj_mosquito/article/details/43306999