今天参加周赛的题目:
完全二叉树的定义:
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 edList<>();
q.offer(root);
int i=0;
while (true){
int len = q.size();
for(;i<len;i++){
TreeNode e = (( edList<TreeNode>) q).get(i);
if(e==null){
len = q.size();
for(;i<len;i++){
if((( edList<TreeNode>) q).get(i)!=null) return false;
}
return true;
}else{
q.offer(e.left);
q.offer(e.right);
}
}
}
}
继续阅读与本文标签相同的文章
上一篇 :
加密货币世界新宠——以太猫
-
Jvm-Sandbox源码分析--启动时加载模块
2026-05-19栏目: 教程
-
免费的分布式事务来了——阿里巴巴Fescar
2026-05-19栏目: 教程
-
升级iOS 13后真能随意换字体?库克言:想多了,字体管理≠换字体
2026-05-19栏目: 教程
-
Java发送邮件必带超时时间配置
2026-05-19栏目: 教程
-
学术研究显示:移动支付让人花钱更多,是真的吗?
2026-05-19栏目: 教程
