Kotlinlearncs.online LogoJava
Return to List

Solve: Binary Tree Count Leaves

Created By: Geoffrey Challen
/ Version: 2020.11.0

Create a method named countLeaves that accepts a single BinaryTree<*>? and counts the number of leaves in the tree. As a reminder, a leaf node has no children. If the passed tree is null, you can return 0, since an empty tree has no nodes and so no leaf nodes.

For reference, cs125.trees.BinaryTree is defined like this:

Related Lessons

Stuck? You may find these lessons helpful: