247. Serialize and Deserialize Binary Tree
Hard · Binary Tree
Design an algorithm to serialize a binary tree to a string and deserialize that string back to the original tree. There is no constraint on the serialization format.
Examples
Example 1 Input: Tree: 1→(2, 3→(4,5)) Output: "1,2,null,null,3,4,null,null,5,null,null" Explanation: Pre-order serialisation with null markers
Constraints
- Tree nodes: 0 to 10⁴, -1000 ≤ val ≤ 1000