Q:

Write a method that checks if a binary tree is strict

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)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now