Pergunta de entrevista da empresa Yahoo

Write a program to count the number of leaves in a binary tree.

Resposta da entrevista

Sigiloso

5 de dez. de 2011

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)

1