Implement two functions: serialize(root) and deserialize(data). The serialize function should convert a binary tree rooted at root into a string representation. The deserialize function should reconstruct the original binary tree from the string produced by serialize. The structure and node values of the tree must be preserved exactly. You may use any serialization format, but both functions must be compatible with each other.
Example 1
Input: root = TreeNode(10, TreeNode(5), TreeNode(15, None, TreeNode(20)))
Output: TreeNode(10, TreeNode(5), TreeNode(15, None, TreeNode(20)))
Explanation: The tree is serialized and deserialized, resulting in the same structure and values.
Example 2
Input: root = None
Output: None
Explanation: An empty tree is serialized and deserialized, resulting in an empty tree.
Example 3
Input: root = TreeNode(-1, TreeNode(-2), TreeNode(-3))
Output: TreeNode(-1, TreeNode(-2), TreeNode(-3))
Explanation: A tree with negative values is serialized and deserialized, preserving structure and values.
Constraints
Case 1
Input: root = TreeNode(7, TreeNode(3, None, TreeNode(4)), TreeNode(9))
Expected: TreeNode(7, TreeNode(3, None, TreeNode(4)), TreeNode(9))
Case 2
Input: root = TreeNode(0)
Expected: TreeNode(0)
Case 3
Input: root = TreeNode(1, None, TreeNode(2, TreeNode(3), None))
Expected: TreeNode(1, None, TreeNode(2, TreeNode(3), None))