Check Completeness of a Binary Tree LeetCode solution in Python

1
class Solution:
2
def isCompleteTree(self, root: Optional[TreeNode]) -> bool:
3
# if not root: return True
4
def node_count(root):
5
if not root:
6
return 0
7
return 1 + node_count(root.left) + node_count(root.right)
8

9
def isCBT(root, i, count):
10
if not root:
11
return True
12
if i >= count:
13
return False
14
return isCBT(root.left, 2 * i + 1, count) and isCBT(
15
root.right, 2 * i + 2, count
16
)
17

18
return isCBT(root, 0, node_count(root))

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0