August 27, 2024

P61 - Count the leaves of a binary tree.

A leaf is a node with no successors.  Write a method leafCount to count them.

scala

scala> Node('x', Node('x'), End).leafCount
res0: Int = 1
Be first to comment
Leave a reply