/**
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* };
*/
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param root TreeNode类
* @return bool布尔型
*/
bool isCompleteTree(TreeNode* root) {
if(root==nullptr)
return true;
queue<TreeNode*> q;
q.push(root);
bool mark=true;
while(!q.empty())
{
int length=q.size();
for(int i=0;i<length;i++)
{
TreeNode* temp=q.front();
q.pop();
if(temp==nullptr)
mark=false;
else
{
if(!mark)
return false;
q.push(temp->left);
q.push(temp->right);
}
}
}
return true;
}
};