---
# System prepended metadata

title: 0958. Check Completeness of a Binary Tree
tags: [Leetcode, BFS, FaceBook, Medium]

---

# 0958. Check Completeness of a Binary Tree
###### tags: `Leetcode` `FaceBook` `Medium` `BFS`
Link: https://leetcode.com/problems/check-completeness-of-a-binary-tree/
## 思路
解法很简单，如果pop出来的元素是null，但是queue的peek不是null，那么就要return false
## Code
```java=
class Solution {
    public boolean isCompleteTree(TreeNode root) {
        Queue<TreeNode> q = new LinkedList<>();
        q.add(root);
        int nodeNum = 1;
        while(!q.isEmpty()){
            TreeNode node = q.poll();
            if(node!=null){
                q.add(node.left);
                q.add(node.right);
            }
            else{
                if(!q.isEmpty() && q.peek()!=null){
                    return false;
                }
            }
        }
        return true;
    }
}
```