手写代码:二叉树序列化反序列化
> 序列化:必须保存一个中序遍历结果,然后外加一个前序或者后序遍历结果
>反序列化:根据两次遍历生成的结果恢复二叉树,代码如下(前序和中序):
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ```TreeNode* helper(vector<int>pre,int startPre,int endPre,vector<int>in,int startIn,int endIn)
|
THE END
> 序列化:必须保存一个中序遍历结果,然后外加一个前序或者后序遍历结果
>反序列化:根据两次遍历生成的结果恢复二叉树,代码如下(前序和中序):
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ```TreeNode* helper(vector<int>pre,int startPre,int endPre,vector<int>in,int startIn,int endIn)
|