12
12
13
13
public class _1325Test {
14
14
private static _1325 .Solution1 solution1 ;
15
+ private static _1325 .Solution2 solution2 ;
15
16
private static TreeNode root ;
16
17
private static TreeNode expected ;
17
18
18
19
@ BeforeClass
19
20
public static void setup () {
20
21
solution1 = new _1325 .Solution1 ();
22
+ solution2 = new _1325 .Solution2 ();
21
23
}
22
24
23
25
@ Test
@@ -65,4 +67,49 @@ public void test5() {
65
67
assertEquals (expected , solution1 .removeLeafNodes (root , 1 ));
66
68
}
67
69
70
+ @ Test
71
+ public void test6 () {
72
+ root = TreeUtils .constructBinaryTree (Arrays .asList (1 , 2 , 3 , 2 , null , 2 , 4 ));
73
+ TreeUtils .printBinaryTree (root );
74
+ expected = TreeUtils .constructBinaryTree (Arrays .asList (1 , null , 3 , null , 4 ));
75
+ TreeUtils .printBinaryTree (expected );
76
+ assertEquals (expected , solution2 .removeLeafNodes (root , 2 ));
77
+ }
78
+
79
+ @ Test
80
+ public void test7 () {
81
+ root = TreeUtils .constructBinaryTree (Arrays .asList (1 , 3 , 3 , 3 , 2 ));
82
+ TreeUtils .printBinaryTree (root );
83
+ expected = TreeUtils .constructBinaryTree (Arrays .asList (1 , 3 , null , null , 2 ));
84
+ TreeUtils .printBinaryTree (expected );
85
+ assertEquals (expected , solution2 .removeLeafNodes (root , 3 ));
86
+ }
87
+
88
+ @ Test
89
+ public void test8 () {
90
+ root = TreeUtils .constructBinaryTree (Arrays .asList (1 , 2 , null , 2 , null , 2 ));
91
+ TreeUtils .printBinaryTree (root );
92
+ expected = TreeUtils .constructBinaryTree (Arrays .asList (1 ));
93
+ TreeUtils .printBinaryTree (expected );
94
+ assertEquals (expected , solution2 .removeLeafNodes (root , 2 ));
95
+ }
96
+
97
+ @ Test
98
+ public void test9 () {
99
+ root = TreeUtils .constructBinaryTree (Arrays .asList (1 , 1 , 1 ));
100
+ TreeUtils .printBinaryTree (root );
101
+ expected = null ;
102
+ TreeUtils .printBinaryTree (expected );
103
+ assertEquals (expected , solution2 .removeLeafNodes (root , 1 ));
104
+ }
105
+
106
+ @ Test
107
+ public void test10 () {
108
+ root = TreeUtils .constructBinaryTree (Arrays .asList (1 , 2 , 3 ));
109
+ TreeUtils .printBinaryTree (root );
110
+ expected = TreeUtils .constructBinaryTree (Arrays .asList (1 , 2 , 3 ));
111
+ TreeUtils .printBinaryTree (expected );
112
+ assertEquals (expected , solution2 .removeLeafNodes (root , 1 ));
113
+ }
114
+
68
115
}
0 commit comments