讨论/算法和数据结构/帮忙改一下代码的错误/
帮忙改一下代码的错误

/**

  • Definition for a binary tree node.

  • struct TreeNode {

  • int val;
    
  • TreeNode *left;
    
  • TreeNode *right;
    
  • TreeNode(int x) : val(x), left(NULL), right(NULL) {}
    
  • };
    */
    class Codec {
    public:

    // Encodes a tree to a single string.
    string serialize(TreeNode* root) {
    string a;
    lize(root, a);
    return a;
    }
    void lize(TreeNode* root, string &a)
    {
    if (root == NULL)
    {
    return ;
    }
    a = a + to_string(root->val);
    lize(root->left, a);
    lize(root->right, a);
    }

    // Decodes your encoded data to tree.
    TreeNode* deserialize(string data) {
    TreeNode *root = new TreeNode();
    root = data[0];
    data.erase(data.begin());
    root->left = deserialize(data);
    root->right = deserialize(data);
    return root;
    }
    };

// Your Codec object will be instantiated and called as such:
// Codec codec;
// codec.deserialize(codec.serialize(root));

展开讨论

反序列化代码有问题吧?