File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed
src/test/java/com/thealgorithms/datastructures/trees Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change 1
- import java .util .*;
1
+ import java .util .LinkedList ; // Replace with specific imports
2
+ import java .util .Queue ;
2
3
3
4
// Define the TreeNode class to represent nodes in the binary tree.
4
5
class TreeNode {
@@ -19,7 +20,9 @@ public class SerializeaBinaryTree {
19
20
// The 'serialize' method converts a binary tree into a string.
20
21
public String serialize (TreeNode root ) {
21
22
// If the tree is empty (root is null), return an empty string.
22
- if (root == null ) return "" ;
23
+ if (root == null ) {
24
+ return "" ;
25
+ }
23
26
24
27
// StringBuilder is used to build the final serialized string efficiently.
25
28
StringBuilder sb = new StringBuilder ();
@@ -59,7 +62,9 @@ public String serialize(TreeNode root) {
59
62
// The 'deserialize' method converts a string back into a binary tree.
60
63
public TreeNode deserialize (String data ) {
61
64
// If the input string is empty, return null (i.e., the tree is empty).
62
- if (data == null || data .isEmpty ()) return null ;
65
+ if (data == null || data .isEmpty ()) {
66
+ return null ;
67
+ }
63
68
64
69
// Split the string by commas to get the serialized node values.
65
70
String [] nodes = data .split ("," );
You can’t perform that action at this time.
0 commit comments