zoukankan      html  css  js  c++  java
  • 110. Balanced Binary Tree(平衡树)

    110. Balanced Binary Tree
    Easy

    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 1:

    Given the following tree [3,9,20,null,null,15,7]:

        3
       / 
      9  20
        /  
       15   7

    Return true.

    Example 2:

    Given the following tree [1,2,2,3,3,null,null,4,4]:

           1
          / 
         2   2
        / 
       3   3
      / 
     4   4
    

    Return false.

    方法一:递归

    这道题是104题的变式题,再求高度的基础上要求平衡树左右子树高度差都小于等于 1。

    时间复杂度:o(n)                     空间复杂度:o(1)

    苟有恒,何必三更眠五更起;最无益,莫过一日暴十日寒。
  • 相关阅读:
    2440中断
    2440内存管理
    printf不定参数
    时钟体系
    Uart串口
    链接脚本与重定位
    指令速记
    OpenOCD-JTAG调试
    ATPCS规则
    ARM三级流水线
  • 原文地址:https://www.cnblogs.com/shaer/p/10563843.html
Copyright © 2011-2022 走看看