当前位置:网站首页>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;
}
总结
- 根据二叉树的性质 — 子树 的位置 必须从左到右,依次排序
- 用栈 保存
边栏推荐
- An article to understand service governance in distributed development
- EViews 12.0软件安装包下载及安装教程
- 柱状图 直方图 条形图 的区别
- 微软 SQL 服务器被黑,带宽遭到破坏
- leetcode 剑指 Offer 46. 把数字翻译成字符串
- leetcode 剑指 Offer 12. 矩阵中的路径
- C# 之 $ – 字符串内插
- 虚幻引擎图文笔记:could not be compiled. Try rebuilding from source manually.问题的解决
- leetcode 剑指 Offer 15. 二进制中1的个数
- Study Notes 11--Direct Construction of Local Trajectories
猜你喜欢

连接mysql报错WARN: Establishing SSL connection without server‘s identity verification is not recommended

MySQL中使用IN 不会走索引分析以及解决办法

【HMS core】【FAQ】HMS Toolkit典型问题合集1

怎么在本地电脑上运行dist文件

shell脚本

How to avoid CMDB becoming a data island?

20220728使用电脑上的蓝牙和汇承科技的蓝牙模块HC-05配对蓝牙串口传输

水电表预付费系统

一个近乎完美的 Unity 全平台热更方案

国外资源加速下载器,代码全部开源
随机推荐
大根堆的创建(视频讲解)
els 方块、背景上色
无法定位程序输入点ucrtbase.abort于动态链接库api-ms-win-crt-runtime-|1-1-0.dll上
Activating data potential Amazon cloud technology reshapes cloud storage "family bucket"
【无标题】
ospf2双点双向重发布(题2)
Devops和低代码的故事:螳螂捕蝉,黄雀在后
函数式接口&Lambda表达式——简单应用笔记
C# 之 $ – 字符串内插
leetcode 剑指 Offer 22. 链表中倒数第k个节点
Unity性能分析 Unity Profile性能分析工具
Matplotlib--绘图标记
新一代开源免费的终端工具,太酷了
Shell系统学习之函数
leetcode 剑指 Offer 46. 把数字翻译成字符串
Using IN in MySQL will not go through index analysis and solutions
百度paddleocr检测训练
Kotlin value class - value class
判断一颗树是否为完全二叉树——视频讲解!!!
leetcode 剑指 Offer 57. 和为s的两个数字