← 返回 amazon 的题目列表Serialize and Deserialize Binary Tree
类型:online_judge
Implement an algorithm to serialize and deserialize a binary tree. Serialization involves converting the tree to a string, and deserialization reconstructs the tree from the string. Assume both input and output are in the form of a binary tree's preorder traversal. Node values are integers. Tree can have up to 10^4 nodes.
Requirements:
Design serialize and deserialize functions.
Include test cases to verify the implementation.
Example:
Input:
# Example binary tree
1
/ \
2 3
/ \
4 5
Output:
[1,2,3,null,null,4,5]
Example
Input
[1,2,3,null,null,4,5]