Problem statement

https://binarysearch.com/problems/Complete-Binary-Tree/

Solution

Equal to Leetcode 0958. Check Completeness of a Binary Tree.

Complexity

It is O(n) for time and space.

Code

class Solution:
    def solve(self, root):
        queue = deque([root])

        while queue:
            node = queue.popleft()
            if not node: return all(i == None for i in queue)
            queue.append(node.left)
            queue.append(node.right)
            
        return True