LeetCode题解之Balanced Binary Tree
1、题目描述

2、问题分析
DFS。
3、代码
bool isBalanced(TreeNode* root) {
if (root == NULL)
return true;
return abs(height(root->left) - height(root->right)) <= && isBalanced(root->left) && isBalanced(root->right);
}
int height(TreeNode *node)
{
if (node == NULL)
return ;
if (node->left == NULL && node->right == NULL)
return ;
return + max(height(node->left), height(node->right));
}
LeetCode题解之Balanced Binary Tree的更多相关文章
- Leetcode 笔记 110 - Balanced Binary Tree
题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For ...
- LeetCode 110. 平衡二叉树(Balanced Binary Tree) 15
110. 平衡二叉树 110. Balanced Binary Tree 题目描述 给定一个二叉树,判断它是否是高度平衡的二叉树. 本题中,一棵高度平衡二叉树定义为: 一个二叉树每个节点的左右两个子树 ...
- 【LeetCode OJ】Balanced Binary Tree
Problem Link: http://oj.leetcode.com/problems/balanced-binary-tree/ We use a recursive auxilar funct ...
- 【一天一道LeetCode】#110. Balanced Binary Tree
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...
- LeetCode OJ 110. Balanced Binary Tree
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...
- 【LeetCode】110. Balanced Binary Tree
题目: Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced bin ...
- LeetCode OJ:Balanced Binary Tree(平衡二叉树)
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...
- leetcode题解:Construct Binary Tree from Inorder and Postorder Traversal(根据中序和后序遍历构造二叉树)
题目: Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assume ...
- LeetCode算法题-Balanced Binary Tree(Java实现)
这是悦乐书的第167次更新,第169篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第26题(顺位题号是110).给定二叉树,判断它是否是高度平衡的.对于此问题,高度平衡二 ...
随机推荐
- Python函数——装饰器
前言 给下面的函数加上运行时间 def fib(n): a, b = 0, 1 for i in range(n): print(b) a, b = b, a+b return b a = fib(5 ...
- Python日常实践(1)——SQL Prompt的Snippets批量整理
引言 个人平时在写sql脚本的时候会使用到SQL Prompt这款插件,除了强大的智能提示和格式化sql语句功能,我还喜欢使用Snippets代码段功能.比如我们可以在查下分析器输入ssf后按Tab键 ...
- LoadRunner通过SiteScope监控MySQL的性能
步骤: 安装 SiteScope 下载 Java 版的MySQL 驱动, 下载地址:http://www.mysql.com/downloads/connector/j/ 下载成功后,把解压缩的 my ...
- 移动端 h5开发相关内容总结(三)
之前写过两篇开发中遇到的问题和解决方案.当时是CSS 和 JavaScript 分开写的.现在写这篇文章的时候感觉很多内容都是有内在联系的,所以不好分开. 给大家分享一下这半年来的感受吧: 知道和理解 ...
- mysql 开发进阶篇系列 27 数据库字符集设置
在安装完数据库后,使用汉字插入到表中,会报错,需要修改字符集类型,如下图所示: -- 插入汉字时报错 INSERT INTO User2 VALUES('张三') -- 查看字符集 SHOW VARI ...
- Android_如何将.9的图片转换成bitmap
//这里也可以是从sd卡上面加载.9图片 Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.ic_launc ...
- aliyun阿里云Maven仓库配置
maven仓库用过的人都知道,国内有多么的悲催.还好有比较好用的镜像可以使用,尽快记录下来.速度提升100倍. http://maven.aliyun.com/nexus/#view-reposito ...
- (原创)UML要点总结
今天我们总结要点: 我们就从这张图慢慢讲. 一.类图部分 基础: 类图→长方形表示.类名在最上栏,下面是数据,第三栏是方法.其存在两种关系:关联和泛化 属性: 全形: 可见性 名:类型 重 ...
- SQL 必知必会·笔记<1>了解SQL
1.1 基本概念 数据库(DataBase) 保存有组织的数据库的容器(通常是一个文件或一组文件). 表(Table) 某种特定数据类型的结构化清单. 模式(Schema) 关于数据库和表的布局及特性 ...
- java高级工程师开放面试题集<二>
临近年关,不少人蠢蠢欲动,有童鞋问我java后端面试会面试什么? 作为一个java后端老鸟,跌打滚爬多次被面试和面试别人,总结了一些经验,希望对大家有所帮助. 特别说明,仅仅针对工作两年以上的java ...