class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param root TreeNode类
* @return bool布尔型
*/
bool isCompleteTree(TreeNode* root) {
if (!root) return false;
// write code here
// println(root);
queue<TreeNode*>q;
q.push(root);
while (q.size()) {
int cnt = q.size();
auto nullpos = 0;
for (int i = 0; i < cnt; i++) {
auto l = q.front();
q.pop();
if (l == NULL) {
while (q.size() && !q.front())
q.pop();
return q.size() == 0;
}
q.push(l->left);
q.push(l->right);
}
}
return true;
}
};