Skip to content

Commit 99a181b

Browse files
refactor 297
1 parent 2e146cb commit 99a181b

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ public TreeNode deserialize(String data) {
4848
}
4949

5050
String[] nodes = data.split(" ");
51-
TreeNode root = new TreeNode(Integer.valueOf(nodes[0]));
51+
TreeNode root = new TreeNode(Integer.parseInt(nodes[0]));
5252
Queue<TreeNode> queue = new LinkedList();
5353
queue.offer(root);
5454
for (int i = 1; i < nodes.length; i++) {
5555
TreeNode curr = queue.poll();
5656
if (!nodes[i].equals("#")) {
57-
curr.left = new TreeNode(Integer.valueOf(nodes[i]));
57+
curr.left = new TreeNode(Integer.parseInt(nodes[i]));
5858
queue.offer(curr.left);
5959
}
6060
if (!nodes[++i].equals("#")) {
61-
curr.right = new TreeNode(Integer.valueOf(nodes[i]));
61+
curr.right = new TreeNode(Integer.parseInt(nodes[i]));
6262
queue.offer(curr.right);
6363
}
6464
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.common.classes.TreeNode;
4+
import com.fishercoder.common.utils.TreeUtils;
5+
import com.fishercoder.solutions._297;
6+
import org.junit.BeforeClass;
7+
import org.junit.Test;
8+
9+
import java.util.Arrays;
10+
11+
import static org.junit.Assert.assertEquals;
12+
13+
public class _297Test {
14+
private static _297.Solution1 solution1;
15+
16+
@BeforeClass
17+
public static void setup() {
18+
solution1 = new _297.Solution1();
19+
}
20+
21+
@Test
22+
public void test1() {
23+
TreeNode root = TreeUtils.constructBinaryTree(Arrays.asList(1, 2, 3, null, null, 4, 5, 6, 7));
24+
TreeUtils.printBinaryTree(root);
25+
String str = solution1.serialize(root);
26+
System.out.println(str);
27+
TreeUtils.printBinaryTree(solution1.deserialize(str));
28+
assertEquals(root, solution1.deserialize(str));
29+
}
30+
31+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy