今天参加周赛的题目:
完全二叉树的定义:
Definition of a complete binary tree from Wikipedia:
In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last level h.
https://leetcode.com/contest/weekly-contest-115/problems/check-completeness-of-a-binary-tree/
解法:层次遍历
public boolean isCompleteTree(TreeNode root) {
if (root == null) return true;
Queue<TreeNode> q = new LinkedList<>();
q.offer(root);
int i=0;
while (true){
int len = q.size();
for(;i<len;i++){
TreeNode e = ((LinkedList<TreeNod