**the test case of runtime errot is [1,2,null,3]**

```
class Solution {
public:
void flatten(TreeNode* root) {
if(!root)
return;
myflatten(root,nullptr);
}
void myflatten(TreeNode* root,TreeNode* bro)
{
if(!root->left&&!root->right&&!bro)
return;
if(!root->left&&!root->right)
{
root->right=bro;
myflatten(bro,nullptr);
}
else if(root->left&&root->right)
{
TreeNode* temp=nullptr;
temp=root->right;
root->right=root->left;
myflatten(root->right,nullptr);
myflatten(root->right,temp);
}
else if(root->left)
{
root->right=root->left;
root->left=nullptr;
myflatten(root->right,bro);
}
else if(root->right)
{
myflatten(root->right,bro);
}
}
};
```