• 题目来源

题目来源

  • C++代码实现
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution
{
public:
bool isCompleteTree(TreeNode* root)
{
if(root == NULL)
{
return true;
} return Sequencetraversal(root);
}
private:
bool Sequencetraversal(TreeNode* root)
{
queue<TreeNode*> dataqueue;
TreeNode* l = NULL;
TreeNode* r = NULL;
bool leaf = false; dataqueue.push(root); while(!dataqueue.empty())
{
root = dataqueue.front();
dataqueue.pop();
l = root->left;
r = root->right; /*一个节点有右孩子没有左孩子,则必不是完全二叉树*/
if(root->right != NULL && root->left == NULL)
{
return false;
} // leaf = true 则表示开启了叶节点的判断
//
if(leaf && (r != NULL || l != NULL) )
{
return false;
} if(l != NULL)
{
dataqueue.push(root->left);
} if(r != NULL)
{
dataqueue.push(root->right);
}
else
{
leaf = true; //有右孩子没有左孩子 开启叶节点的判断
}
} return true;
} };

958. Check Completeness of a Binary Tree的更多相关文章

  1. leetcode 958. Check Completeness of a Binary Tree 判断是否是完全二叉树 、222. Count Complete Tree Nodes

    完全二叉树的定义:若设二叉树的深度为h,除第 h 层外,其它各层 (1-h-1) 的结点数都达到最大个数,第 h 层所有的结点都连续集中在最左边,这就是完全二叉树. 解题思路:将树按照层进行遍历,如果 ...

  2. LeetCode 958. Check Completeness of a Binary Tree

    原题链接在这里:https://leetcode.com/problems/check-completeness-of-a-binary-tree/ 题目: Given a binary tree, ...

  3. 【leetcode】958. Check Completeness of a Binary Tree

    题目如下: Given a binary tree, determine if it is a complete binary tree. Definition of a complete binar ...

  4. 【LeetCode】958. Check Completeness of a Binary Tree 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 BFS DFS 日期 题目地址:https://le ...

  5. [Swift]LeetCode958. 二叉树的完全性检验 | Check Completeness of a Binary Tree

    Given a binary tree, determine if it is a complete binary tree. Definition of a complete binary tree ...

  6. 115th LeetCode Weekly Contest Check Completeness of a Binary Tree

    Given a binary tree, determine if it is a complete binary tree. Definition of a complete binary tree ...

  7. Leetcode958. Check Completeness of a Binary Tree二叉树的完全验证性

    给定一个二叉树,确定它是否是一个完全二叉树. 百度百科中对完全二叉树的定义如下: 若设二叉树的深度为 h,除第 h 层外,其它各层 (1-h-1) 的结点数都达到最大个数,第 h 层所有的结点都连续集 ...

  8. 图论-完全二叉树判定-Check Completeness of a Binary Tree

    2020-02-19 13:34:28 问题描述: 问题求解: 判定方式就是采用层序遍历,对于一个完全二叉树来说,访问每个非空节点之前都不能访问过null. public boolean isComp ...

  9. Check whether a given Binary Tree is Complete or not 解答

    Question A complete binary tree is a binary tree in which every level, except possibly the last, is ...

随机推荐

  1. git 提交项目到远程仓库,简单实现忽略 node_modules文件

    在项目根目录中创建 .gitignore文件 在文件中添加你要忽略的文件 .DS_Store node_modules /dist # local env files .env.local .env. ...

  2. MATLAB实现OTSU

    目录 1.OTSU算法原理简述: 2.MATLAB实现代码 @ 1.OTSU算法原理简述: 最大类间方差是由日本学者大津(Nobuyuki Otsu)于1979年提出,是一种自适应的阈值确定方法.算法 ...

  3. Htmlunit 设置缓存文件

    起因:最近用Htmlunit爬取网页.demo运行起来后,发现速度相当慢,一直在不停的加载js文件,偶尔还会报错,js超时等.抓包工具看了一下请求,发现一直在不停的下载js文件.按理说请求过js文件后 ...

  4. 支付宝API

    1. 业务场景描述:在我们的爱旅行项目中,用户只有报名并且付款之后才能算作参加旅行团成功,因此必须提供快速便捷的支付功能:这里,我们选择了阿里的支付宝api来实现快捷支付,基于此,我们向蚂蚁金服发起申 ...

  5. python高级 之(一) --- 函数类型

    函数 模块 模块: 一个py文件就是一个模块, 每个模块之间是可以相互访问的 访问之前需要进行导入 分类: 1.系统提供的模块 math random 2.自己自定义的,自己封装的常用功能的的py文件 ...

  6. spring 给容器中注册组件的几种方式

    1.@Bean 导入第三方的类或包的组件 2.包扫描+组件的标注注解(@ComponentScan: @Controller,@service,@Reponsitory,@Componet), 自己写 ...

  7. 使用Zabbix进行IPMI监控

    1.    安装IPMItool软件包 # yum -y install OpenIPMI OpenIPMI-devel ipmitoolfreeipmi 2.    配置Zabbix 服务器端配置z ...

  8. 强化学习应用于游戏Tic-Tac-Toe

    Tic-Tac-Toe游戏为3*3格子里轮流下棋,一方先有3子成直线的为赢家. 参考代码如下,我只删除了几个没用的地方: ####################################### ...

  9. java-最大公约数

    4和2的最大公约数是2呀

  10. web端 微软 RDLC 报表插件 宽大于高 横向打印失效 解决方案

    起因于系统报表工具使用的RDLC,本地测试一直使用的纵向打印,未测试过横向打印