countHalfNodes<T> function
Implementation
int countHalfNodes<T>(BinaryTreeNode<T>? root) {
if (root == null) return 0;
int count = 0;
if ((root.left == null) != (root.right == null)) count = 1;
return count + countHalfNodes(root.left) + countHalfNodes(root.right);
}