Skip to content

Commit 2d345d8

Browse files
1 parent cb0c01b commit 2d345d8

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

src/Practice.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,20 @@ public static int nbSum(TreeNode<Integer> root) {
286286
* @return the count of nodes that do not have siblings, EXCLUDING THE ROOT
287287
*/
288288
public static int onlyChildCount(TreeNode<?> root) {
289-
return 0;
289+
if (root == null) {
290+
return 0;
291+
}
292+
293+
int count = 0;
294+
295+
for (TreeNode<?> child : root.children) {
296+
if (root.children.size() == 1) {
297+
count++;
298+
}
299+
count += onlyChildCount(child);
300+
}
301+
302+
return count;
290303
}
291304

292305
/**

0 commit comments

Comments
 (0)