implemented the LeafCounter class to count the number of leaves without building the tree