Tree/count_leaf_nodes library

🌳 Count Leaf Nodes in a Binary Tree

Counts the number of leaf nodes (nodes with no children) 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 = countLeafNodes(root);
// count: 2

Functions

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