from re import T
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param root TreeNode类 
# @return bool布尔型
#
class Solution:
    def isCompleteTree(self , root: TreeNode) -> bool:
        # write code here
        if root is None:
            return False
        qe = [root]
        flag = True
        while len(qe)>0:
            this = qe.pop(0)
            if this.left is not None and this.right is not None:
                if flag==False:
                    return False
                qe.append(this.left)
                qe.append(this.right)
            elif this.left is not None and this.right is None:
                if flag==False:
                    return False
                flag = False
                qe.append(this.left)
            elif this.right is not None and this.left is None:
                return False
            else:
                flag = False
        
        return True