Given a binary tree, determine if it is height-balanced.

For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.

Example

Given binary tree A = {3,9,20,#,#,15,7}, B = {3,#,20,15,7}

 A)  3            B)    3
/ \ \
9 20 20
/ \ / \
15 7 15 7

The binary tree A is a height-balanced binary tree, but B is not.

For this problem I am thinking to use recursive method to deal with it.

1. The banlance of the tree need to be made sure with the balance of the left tree and right tree. Then the height of right tree and left tree difference should not be larger than one.

2. The problem size is reducing.

3. When the tree is null or is leave base case is done. It is banlanced and height is 0 or 1;

LintCode Balanced Binary Tree的更多相关文章

  1. CCI4.4/LintCode Balanced Binary Tree, Binary Tree, Binary Search Tree

    Binary Tree: 0到2个子节点; Binary Search Tree: 所有左边的子节点 < node自身 < 所有右边的子节点: 1. Full类型: 除最下面一层外, 每一 ...

  2. Leetcode 笔记 110 - Balanced Binary Tree

    题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For ...

  3. 110.Balanced Binary Tree Leetcode解题笔记

    110.Balanced Binary Tree Given a binary tree, determine if it is height-balanced. For this problem, ...

  4. [Leetcode][JAVA] Minimum Depth of Binary Tree && Balanced Binary Tree && Maximum Depth of Binary Tree

    Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the n ...

  5. 【leetcode】Balanced Binary Tree(middle)

    Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...

  6. 33. Minimum Depth of Binary Tree && Balanced Binary Tree && Maximum Depth of Binary Tree

    Minimum Depth of Binary Tree OJ: https://oj.leetcode.com/problems/minimum-depth-of-binary-tree/ Give ...

  7. [CareerCup] 4.1 Balanced Binary Tree 平衡二叉树

    4.1 Implement a function to check if a binary tree is balanced. For the purposes of this question, a ...

  8. 平衡二叉树(Balanced Binary Tree)

    平衡二叉树(Balanced Binary Tree)/AVL树:

  9. [LeetCode#110, 112, 113]Balanced Binary Tree, Path Sum, Path Sum II

    Problem 1 [Balanced Binary Tree] Given a binary tree, determine if it is height-balanced. For this p ...

随机推荐

  1. JavaScript 获取当前时间戳

    转自博客(http://blog.sina.com.cn/s/blog_8772845101019kg5.html) JavaScript 获取当前时间戳:第一种方法: var timestamp = ...

  2. 系统收到了多个不同的 Content-Disposition 标头。为了避免遭到 HTTP 响应拆分攻击,这种情况是不允许的。

    今天使用Struts2进行上传下载的时候发现了一个现象 我的Struts2配置文件 <action name="share_ExportExcel" class=" ...

  3. 深入浅出设计模式——单例模式(Singleton Pattern)

    模式动机对于系统中的某些类来说,只有一个实例很重要,例如,一个系统中可以存在多个打印任务,但是只能有一个正在工作的任务:一个系统只能有一个窗口管理器或文件系统:一个系统只能有一个计时工具或ID(序号) ...

  4. HDU-4527 小明系列故事——玩转十滴水 模拟

    题意:就是平时玩的十滴水游戏,游戏者拥有一定的水滴,能够滴在某些位置,如果一个点上的体积超过了4就会爆炸,向四周传递一个小水滴.该题就是要求模拟这个过程. 分析:这里有一个问题就是不能够使用递归来处理 ...

  5. iOS - C 基本语法

    1.数据类型 2.常量 1)凡是整数数字常量一律是 int 型. 2)typedef 和 define. typedef 定义类型, #define 只是字符串替换. 3)在编写整形常量时,可以在常量 ...

  6. Android Gradle 完整指南

    为什么需要学Gradle? Gradle 是 Android 现在主流的编译工具,虽然在Gradle 出现之前和之后都有对应更快的编译工具出现,但是 Gradle 的优势就在于它是亲儿子,Gradle ...

  7. java complier compliance level问题引发的思考

    http://blog.csdn.net/shan9liang/article/details/17266519 ******************************************* ...

  8. OpenGL的API函数使用手册

    (一)OpenGL函数库 格式: <库前缀><根命令><可选的参数个数><可选的参数类型> 库前缀有 gl.glu.aux.glut.wgl.glx.a ...

  9. 百度地图 判断marker是否在多边形内

    昨天画了圆形,判marker是否存在圆形内.今天来画多边形,判断marker在多边形内. 需要引入一个js      <script type="text/javascript&quo ...

  10. nodejs的第二天学习笔记

    一. Shell: 1) 常用的shell a) CMD: window+r 打开面板中输入cmd 回车   特点:很多都是window下面的指令 b) powerShell:   特点:它能够兼容w ...