算法1
(暴力枚举) $O(n^2)$
BFS
时间复杂度
参考文献
java 代码
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
public boolean isCompleteTree(TreeNode root) {
Queue<TreeNode> q = new LinkedList<>();
q.offer(root);
while(!q.isEmpty())
{
TreeNode cur=q.poll();
if(cur==null)
{
//查队列中后面是否有非空个节点
while(!q.isEmpty())
{
TreeNode temp = q.peek();
if(temp!=null) return false;
else q.poll();
}
}
else
{
q.offer(cur.left);
q.offer(cur.right);
}
}
return true;
}
}