Hard

Quiz

#297 Serialize and Deserialize Binary Tree

APPROACH

Serialization converts a data structure into a format suitable for storage or transmission, after which it can be reconstructed in the same or another environment.

Design an algorithm to serialize a binary tree to a string and deserialize that string back to the original tree structure. The encoding format is entirely your choice — correctness of the round-trip is the only requirement.

Clarification: The input/output format is the same as how LeetCode serializes a binary tree. You do not necessarily need to follow this format, so please be creative and come up with different approaches yourself.

Example 1:

Input: root = [1,2,3,null,null,4,5]
Output: [1,2,3,null,null,4,5]

Example 2:

Input: root = []
Output: []
1 of 4
1:00

What is the optimal approach for this problem?