Q:

Write a method that checks if a binary tree is strict

belongs to collection: java exercises (medium level )

0

A binary tree is strict when all nodes have either two or zero child nodes.
Write a method that checks if a binary tree is strict.
TreeNode API methods: node.left() and node.right().

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

public Boolean isStrictTree(TreeNode node) {
if (node == null) {
    return true;
}
if ((node.left() == null && node.right() != null) || (node.left() != null && node.right() == null)) {
    return false;
}
return isStrictTree(node.left()) && isStrictTree(node.right());
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write a method that checks if there is at least on... >>
<< write a method that returns true if it is possible...