MCPcopy Index your code
hub / github.com/joowani/binarytree / leaf_count

Method leaf_count

binarytree/__init__.py:1075–1097  ·  view source on GitHub ↗

Return the total number of leaf nodes in the binary tree. A leaf node is a node with no child nodes. :return: Total number of leaf nodes. :rtype: int **Example**: .. doctest:: >>> from binarytree import Node >>> >>> roo

(self)

Source from the content-addressed store, hash-verified

1073
1074 @property
1075 def leaf_count(self) -> int:
1076 """Return the total number of leaf nodes in the binary tree.
1077
1078 A leaf node is a node with no child nodes.
1079
1080 :return: Total number of leaf nodes.
1081 :rtype: int
1082
1083 **Example**:
1084
1085 .. doctest::
1086
1087 >>> from binarytree import Node
1088 >>>
1089 >>> root = Node(1)
1090 >>> root.left = Node(2)
1091 >>> root.right = Node(3)
1092 >>> root.left.right = Node(4)
1093 >>>
1094 >>> root.leaf_count
1095 2
1096 """
1097 return _get_tree_properties(self).leaf_count
1098
1099 @property
1100 def is_balanced(self) -> bool:

Callers

nothing calls this directly

Calls 1

_get_tree_propertiesFunction · 0.85

Tested by

no test coverage detected