O(1) Solution:

  • 0
    class Codec {
        TreeNode* hehe;
        // Encodes a tree to a single string.
        string serialize(TreeNode* root) {
            hehe = root;
            return "hehe";
        // Decodes your encoded data to tree.
        TreeNode* deserialize(string data) {
            return hehe;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.