countLeafNodes<T> function

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

Implementation

int countLeafNodes<T>(BinaryTreeNode<T>? root) {
  if (root == null) return 0;
  if (root.left == null && root.right == null) return 1;
  return countLeafNodes(root.left) + countLeafNodes(root.right);
}