Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc927d7c

Browse files
edit 297
1 parent71c7431 commitc927d7c

File tree

1 file changed

+13
-5
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+13
-5
lines changed

‎src/main/java/com/fishercoder/solutions/_297.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@
66
importjava.util.Queue;
77

88
/**
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.
1218
1319
For example, you may serialize the following tree
1420
@@ -18,7 +24,9 @@
1824
/ \
1925
4 5
2026
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.
2230
2331
Note: Do not use class member/global/static variables to store states. Your serialize and deserialize algorithms should be stateless.
2432
*/
@@ -27,7 +35,7 @@ public class _297 {
2735
/**The idea is very straightforward:
2836
use "#" as the terminator, do BFS, level order traversal to store all nodes values into a StringBuilder.
2937
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,
3139
then eventually just return the root.
3240
*/
3341

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp