Check Completeness of a Binary Tree LeetCode solution in Python
1class Solution:2def isCompleteTree(self, root: Optional[TreeNode]) -> bool:3# if not root: return True4def node_count(root):5if not root:6return 07return 1 + node_count(root.left) + node_count(root.right)89def isCBT(root, i, count):10if not root:11return True12if i >= count:13return False14return isCBT(root.left, 2 * i + 1, count) and isCBT(15root.right, 2 * i + 2, count16)1718return isCBT(root, 0, node_count(root))