MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / count_nodes

Function count_nodes

data_structures/binary_tree/distribute_coins.py:82–90  ·  view source on GitHub ↗

>>> count_nodes(None) 0

(node: TreeNode | None)

Source from the content-addressed store, hash-verified

80
81 # Validation
82 def count_nodes(node: TreeNode | None) -> int:
83 """
84 >>> count_nodes(None)
85 0
86 """
87 if node is None:
88 return 0
89
90 return count_nodes(node.left) + count_nodes(node.right) + 1
91
92 def count_coins(node: TreeNode | None) -> int:
93 """

Callers 1

distribute_coinsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected