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

Commit99a181b

Browse files
refactor 297
1 parent2e146cb commit99a181b

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-
TreeNoderoot =newTreeNode(Integer.valueOf(nodes[0]));
51+
TreeNoderoot =newTreeNode(Integer.parseInt(nodes[0]));
5252
Queue<TreeNode>queue =newLinkedList();
5353
queue.offer(root);
5454
for (inti =1;i <nodes.length;i++) {
5555
TreeNodecurr =queue.poll();
5656
if (!nodes[i].equals("#")) {
57-
curr.left =newTreeNode(Integer.valueOf(nodes[i]));
57+
curr.left =newTreeNode(Integer.parseInt(nodes[i]));
5858
queue.offer(curr.left);
5959
}
6060
if (!nodes[++i].equals("#")) {
61-
curr.right =newTreeNode(Integer.valueOf(nodes[i]));
61+
curr.right =newTreeNode(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+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.common.classes.TreeNode;
4+
importcom.fishercoder.common.utils.TreeUtils;
5+
importcom.fishercoder.solutions._297;
6+
importorg.junit.BeforeClass;
7+
importorg.junit.Test;
8+
9+
importjava.util.Arrays;
10+
11+
importstaticorg.junit.Assert.assertEquals;
12+
13+
publicclass_297Test {
14+
privatestatic_297.Solution1solution1;
15+
16+
@BeforeClass
17+
publicstaticvoidsetup() {
18+
solution1 =new_297.Solution1();
19+
}
20+
21+
@Test
22+
publicvoidtest1() {
23+
TreeNoderoot =TreeUtils.constructBinaryTree(Arrays.asList(1,2,3,null,null,4,5,6,7));
24+
TreeUtils.printBinaryTree(root);
25+
Stringstr =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)

[8]ページ先頭

©2009-2025 Movatter.jp