当前位置:网站首页>Determine whether a tree is a complete binary tree - video explanation!!!
Determine whether a tree is a complete binary tree - video explanation!!!
2022-07-30 09:54:00 【Learning to pursue high efficiency】
7. (视频讲解)判断一棵树 是否为 完全二叉树
判断一棵树是否为完全二叉树
注意:队列中 元素也可以是 null
// 判断一棵树是不是完全二叉树
boolean isCompleteTree(TreeNode root) {
if(root == null) return true;
Queue<TreeNode> queue = new LinkedList<>();
queue.offer(root);
while (!queue.isEmpty()) {
TreeNode cur = queue.poll();
if(cur != null) {
queue.offer(cur.left);
queue.offer(cur.right);
}else {
break;
}
}
while (!queue.isEmpty()) {
TreeNode cur = queue.peek();
if(cur != null) {
//不是满二叉树
return false;
}else {
queue.poll();
}
}
return true;
}
总结
- 根据二叉树的性质 — 子树 的位置 必须从左到右,依次排序
- 用栈 保存
边栏推荐
- leetcode 剑指 Offer 10- I. 斐波那契数列
- Use the R language to read the csv file into a data frame, and then view the properties of each column.
- 读书笔记:《这才是心理学:看穿伪心理学的本质(第10版)》
- 企业数字化建设,自研还是采购?
- Liunx服务器安装SVN(安装包版)
- C#中Config文件中,密码的 特殊符号的书写方法。
- 容器技术 -- 简单了解 Kubernetes 的对象
- ThreadLocal内存泄漏是伪命题?
- 功能测试、UI自动化测试(web自动化测试)、接口自动化测试
- Day113.尚医通:微信登录二维码、登录回调接口
猜你喜欢
随机推荐
树莓派_烧写Raspberry官方镜像系统
conda 导出/导出配置好的虚拟环境
Taosi TDengine 2.6+ optimization parameters
0729放假自习
Detailed description of iperf3 parameter options
统一异常处理导致ResponseBodyAdvice失效
激活数据潜力 亚马逊云科技重塑云上存储“全家桶”
leetcode 剑指 Offer 12. 矩阵中的路径
shell脚本
PyQt5-在窗口上绘制文本
函数式接口&Lambda表达式——简单应用笔记
A new generation of free open source terminal tool, so cool
ThreadLocal内存泄漏是伪命题?
实施敏捷过程中这些常见的问题你可曾遇到?
How to run dist file on local computer
leetcode 剑指 Offer 47. 礼物的最大价值
The use of qsort function and its analog implementation
【 HMS core 】 【 】 the FAQ HMS Toolkit collection of typical questions 1
水电表预付费系统
Google Cloud Spanner的实践经验




![MySQL [operator]](/img/dd/2bf6ccd731299dc405bc06e03e1550.png)




