countHalfNodes<T> function

int countHalfNodes<T>(
  1. BinaryTreeNode<T>? root
)

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);
}