"A leaf is a node with no successors. Write a method leaf-count to count them."
(deftest p61-count-leaves (is (= (leaf-count '[x [x [x nil nil] nil] [x nil nil]]) 2)))
I simply walked the tree and counted all the leaves. Both functions, for detecting leaves and walking the tree, existed from previous exercises. See the solution on Github.
No comments:
Post a Comment