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.

解题思路:

递归即可,JAVA实现如下:

    public boolean isBalanced(TreeNode root) {
if(root==null)
return true;
if(Math.abs(maxDepth(root.left)-maxDepth(root.right))>1)
return false;
return isBalanced(root.left)&&isBalanced(root.right);
}
static public int maxDepth(TreeNode root) {
if(root==null)
return 0;
return Math.max(maxDepth(root.left), maxDepth(root.right))+1;
}

最新文章

  1. GC
  2. YUM仓库服务
  3. linux中mysql如何设置为开机启动
  4. JAVA 多线程和并发学习笔记(四)
  5. LSD-SLAM深入学习(4)-非ROS改造
  6. 测试文档锁:doc.LockDocument()
  7. 【SpringMVC】SpringMVC系列9之Model数据返回到View
  8. CentOS7+Redis Live安装配置
  9. Android使用MVP时应该注意的问题
  10. 有关IT的小笑话
  11. [Swust 549]--变位词(vector水过)
  12. Swift开发学习(两):Playground
  13. wireshark抓包图解 TCP三次握手/四次挥手详解[转]
  14. bzoj 5297: [Cqoi2018]社交网络
  15. hive动态分区和混合分区
  16. webpack2入门概念
  17. 原创《weex面向未来的架构》
  18. Azure DevOps Server:Git权限设置
  19. C#内存映射文件消息队列实战演练(MMF—MQ)
  20. ASP.NET :Virtual Application vs Virtual Directory

热门文章

  1. Iosapp升级版本步骤
  2. Android 日期对话框DatePickerDialog
  3. python tcp,udp简单使用
  4. 转: 使用maven给spring项目打可直接运行的jar包(配置文件内置外置的打法)
  5. mongodb文档的CRUD
  6. mysql去掉空格换行符
  7. Async.js解决Node.js操作MySQL的回调大坑
  8. UNP学习笔记(第八章 基本UDP套接字编程)
  9. pom.xml基础配置
  10. java 中 instanceof 和 isInstance区别