File tree 1 file changed +6
-3
lines changed
src/main/java/com/fishercoder/solutions
1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -151,6 +151,7 @@ public TreeNode deserialize(String data) {
151
151
return root ;
152
152
}
153
153
}
154
+
154
155
public static class Solution4 {
155
156
private static final String NULL_SYMBOL = "X" ;
156
157
private static final String DELIMITER = "," ;
@@ -159,8 +160,9 @@ public static class Solution4 {
159
160
public String serialize (TreeNode root ) {
160
161
161
162
// If we have a null symbol, encode it to NULL_SYMBOL
162
- if (root == null )
163
+ if (root == null ) {
163
164
return NULL_SYMBOL + DELIMITER ;
165
+ }
164
166
165
167
String leftSubtree = serialize (root .left );
166
168
String rightSubtree = serialize (root .right );
@@ -176,12 +178,13 @@ public TreeNode deserialize(String data) {
176
178
return deserializeHelper (nodesLeftToSerialize );
177
179
178
180
}
179
- private TreeNode deserializeHelper (Queue <String > nodesLeft ){
181
+
182
+ private TreeNode deserializeHelper (Queue <String > nodesLeft ) {
180
183
181
184
// remove the node
182
185
String nodeLeftToSerialize = nodesLeft .poll ();
183
186
// base case
184
- if (nodeLeftToSerialize .equals (NULL_SYMBOL )){
187
+ if (nodeLeftToSerialize .equals (NULL_SYMBOL )) {
185
188
return null ;
186
189
}
187
190
TreeNode newNode = new TreeNode (Integer .valueOf (nodeLeftToSerialize ));
You can’t perform that action at this time.
0 commit comments