You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/main/java/com/fishercoder/solutions/_297.java
+13-5
Original file line number
Diff line number
Diff line change
@@ -6,9 +6,15 @@
6
6
importjava.util.Queue;
7
7
8
8
/**
9
-
* Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment.
10
-
11
-
Design an algorithm to serialize and deserialize a binary tree. There is no restriction on how your serialization/deserialization algorithm should work. You just need to ensure that a binary tree can be serialized to a string and this string can be deserialized to the original tree structure.
9
+
* 297. Serialize and Deserialize Binary Tree
10
+
*
11
+
* Serialization is the process of converting a data structure or object into a sequence of bits
12
+
* so that it can be stored in a file or memory buffer,
13
+
* or transmitted across a network connection link to be reconstructed later in the same or another computer environment.
14
+
* Design an algorithm to serialize and deserialize a binary tree.
15
+
* There is no restriction on how your serialization/deserialization algorithm should work.
16
+
* You just need to ensure that a binary tree can be serialized to a string and this string can
17
+
* be deserialized to the original tree structure.
12
18
13
19
For example, you may serialize the following tree
14
20
@@ -18,7 +24,9 @@
18
24
/ \
19
25
4 5
20
26
21
-
as "[1,2,3,null,null,4,5]", just the same as how LeetCode OJ serializes a binary tree. You do not necessarily need to follow this format, so please be creative and come up with different approaches yourself.
27
+
as "[1,2,3,null,null,4,5]",
28
+
just the same as how LeetCode OJ serializes a binary tree.
29
+
You do not necessarily need to follow this format, so please be creative and come up with different approaches yourself.
22
30
23
31
Note: Do not use class member/global/static variables to store states. Your serialize and deserialize algorithms should be stateless.
24
32
*/
@@ -27,7 +35,7 @@ public class _297 {
27
35
/**The idea is very straightforward:
28
36
use "#" as the terminator, do BFS, level order traversal to store all nodes values into a StringBuilder.
29
37
30
-
When deserializing, also, use a queue: pop the root into the queue first, then use a for loop to construct each node,
38
+
When deserializing, also use a queue: pop the root into the queue first, then use a for loop to construct each node,
0 commit comments