297. Serialize and Deserialize Binary Tree
Practice Serialize and Deserialize Binary Tree for free on NudgeCode: Hard, Binary Tree pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Design an algorithm to turn a binary tree into a string (serialize) and turn that string back into the same tree (deserialize). Any string format works, as long as the round trip gives back the original tree.
The tests check that deserialize(serialize(root)) equals root.
Example
root = [1,2,3,null,null,4,5] -> [1,2,3,null,null,4,5]
Constraints
- 0 <= number of nodes <= 10^4
- -1000 <= Node.val <= 1000