Write a program to count the number of leaves in a binary tree.
Anonymous
def count_leaves(root): if not root: return 0 elif not root.left and not root.right: return 1 else: return count_leaves(root.left) + count_leaves(root.right)
Check out your Company Bowl for anonymous work chats.