Tree/count_half_nodes library

🌳 Count Half Nodes in a Binary Tree

Counts the number of half nodes (nodes with exactly one child) in a binary tree.

Time complexity: O(n) Space complexity: O(h)

Example:

final root = BinaryTreeNode<int>(10);
root.left = BinaryTreeNode<int>(5);
root.right = BinaryTreeNode<int>(15);
final count = countHalfNodes(root);
// count: 0

Functions

countHalfNodes<T>(BinaryTreeNode<T>? root) → int