Eine nicht rekursive Lösung, die eine Laufzeit von O(n) hat, wäre wie folgendes:

def count_nodes(node):
    count = 0
    nodes_to_search = [node]

    while len(nodes_to_search) > 0:
        count += len(nodes_to_search)

        new_nodes = []
        for node_to_search in nodes_to_search:
            if node_to_search.left is not None:
                new_nodes.append(node_to_search.left)
            if node_to_search.right is not None:
                new_nodes.append(node_to_search.right)
        nodes_to_search = new_nodes
spam fails_task lang_mismatch pii not_appropriate hate_speech sexual_content quality toxicity humor helpfulness creativity violence