博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
110. Balanced Binary Tree(平衡树)
阅读量:7082 次
发布时间:2019-06-28

本文共 617 字,大约阅读时间需要 2 分钟。

110. Balanced Binary Tree
Easy
108994FavoriteShare

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)

 

转载于:https://www.cnblogs.com/shaer/p/10563843.html

你可能感兴趣的文章
.NET Core中的去虚
查看>>
前端大神用React刻了一个Windows XP
查看>>
10种避免大型部署的方法
查看>>
Yelp的实时流技术之二:将MySQL表数据变更实时流到Kafka中
查看>>
数据不可变之linked-in/rocketdata
查看>>
Java 10新特性前瞻
查看>>
从蚂蚁金服实践入手,带你深入了解 Service Mesh
查看>>
通过DevOps考古学了解生产环境
查看>>
nginx lua指令执行顺序
查看>>
新书问答:Agile Management
查看>>
精益企业中架构师的角色
查看>>
Chrome开发者工具中关于“Deferred long-running timer task(s) ”的警告
查看>>
Windows 下使用 MinGW 编译安装 (G)vim 添加 Lua 等编程语言支持
查看>>
Objective-C基本数据类型
查看>>
利用localStorage本地储存js文件
查看>>
[聊一聊系列]聊一聊百度移动端首页前端速度那些事儿
查看>>
shell script编程小结——附带实例
查看>>
在 Laravel 项目中使用 Glup 之 Laravel-Elixir
查看>>
Nginx、CGI、FastCGI、PHP-CGI、PHP-FPM处理流程
查看>>
Tornado 4.3文档翻译: web框架-RequestHandler和Application 类
查看>>