110. serialize and deserialize binary tree
medium - accepted / - tried
Can you transform(serialize) a binary tree into a string and restore(deserialize) a binary tree from the string? Just like what JSON.stringify() and JSON.parse() do.
For example, for a tree from 91. invert a binary tree
BFE.dev would serialize it to
But there are more ways of doing it rather than above, any would be fine as long as your
serialize() work as a pair.
Your code is tested like this:
const tree1 = ... expect(typeof serialize(tree1)).toBe('string') const tree2 = deserialize(serialize(tree1)) expect(isIdentical(tree1, tree2)).toBe(true)
Binary tree in this problem consists of value of integers.