My idea is basically flatten binary tree recursively. with the flatten_helper function to flatten a sub-tree from root, and return this sub-tree's last node in flattened linked list.

BUT, this causes RuntimeError with input {1, #, 2}, after walking through for a lot of times, i still cannot figure out why. Is there anyone can help and pick the bug out??

```
void flatten(TreeNode *root) {
if ( NULL==root ) { return; }
flatten_helper(root);
}
TreeNode * flatten_helper(TreeNode * root){
if ( NULL==root->left && NULL==root->right ){//Leaf Node last node is root
return root;
} else if ( NULL==root->left ){
//root->right is already root->right
TreeNode * right_last = flatten_helper(root->right);
return right_last;
} else if ( NULL==root->right ){
TreeNode * left_last = flatten_helper(root->left);
root->right = root->left;
return left_last;
} else {
TreeNode * left_last = flatten_helper(root->left);
TreeNode * right_last = flatten_helper(root->right);
left_last->right = root->right;
root->right = root->left;
right_last->right = NULL;
return right_last;
}
}
```