Z31
Serialize and Deserialize Binary Tree
Problem Statement & Objective
Design an algorithm to serialize and deserialize a binary tree to and from a string format.
Function Signature (Python)
serialize_and_deserialize_binary_tree(root: list) -> listInput & Output Contract
Output Rule:[seri, agac]. seri '#' preorder metnidir. agac, sondaki boş null'ları atılmış düzey sırasıdır.
Örnek seri: '1,2,#,#,3,4,#,#,5,#,#'
System Constraints
0 <= agac.length <= 10^4
-1000 <= değer <= 1000 veya nullExample Execution Walkthrough
agac = [1, 2, 3, null, null, 4, 5]
seri = 1,2,#,#,3,4,#,#,5,#,#
yeniden kurulan = [1, 2, 3, null, null, 4, 5]
agac = [1, 2]
seri = 1,2,#,#,#
yeniden kurulan = [1, 2] (sondaki null yazılmaz)
agac = [1, null, 2]
seri = 1,#,2,#,#
yeniden kurulan = [1, null, 2]Example Test Scenarios (3)
Example 1
Input:
[[1,2,3,null,null,4,5]]Expected Output:
["1,2,#,#,3,4,#,#,5,#,#",[1,2,3,null,null,4,5]]Example 2: Boş
Input:
[[]]Expected Output:
["",[]]Example 3: Tek Düğüm
Input:
[[1]]Expected Output:
["1,#,#",[1]]