/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
public int height(TreeNode root){
if(root == null)
return 0;
int left_height = height(root.left);
int right_height = height(root.right);
return 1 + (left_height > right_height ? left_height : right_height);
}
public boolean isBalanced(TreeNode root) {
if(root == null){
return true;
}
int left_height = height(root.left);
int right_height = height(root.right);
if(Math.abs(left_height - right_height) > 1){
return false;
}
else{
return isBalanced(root.left) && isBalanced(root.right);
}
}
}

最新文章

  1. iOS Xcode behaviors个人常用Debug配置
  2. 【转】STM32定时器输出比较模式中的疑惑
  3. windows下的文件到linux下乱码 iconv 修改文件编码
  4. 以WCF安全认证方式调用通用权限管理系统获取基础信息资料
  5. django: template variable
  6. Linux内核和根文件系统引导加载程序
  7. [原]关于在 iOS 中支持 DLNA
  8. SSH整合总结(xml与注解)
  9. shiro入门示例
  10. Mysql 范围查询优化
  11. 携程Apollo(阿波罗)配置中心用户管理和部门管理
  12. 使用mongoskin操作MongoDB
  13. 第5次作业 -- 基于Jmeter的 性能测试
  14. <转>ajax 同步异步问题
  15. mysql打开binlog
  16. DHacker 汉化
  17. 微信公众平台测试帐号的注册与使用(自己的服务器<---->微信后台<---->测式公众号)
  18. BOM及DOM及事件
  19. Chapter 3 Phenomenon——17
  20. angularjs的Controller as

热门文章

  1. sql查重去除id最小值
  2. java方法调用顺序
  3. shell脚本常用命令汇总
  4. 网鼎杯2020青龙组writeup-web
  5. 00004-form 表单的清空、重置 (jquery)
  6. 萌新学习SpringMVC
  7. 「雕爷学编程」Arduino动手做(39)——DS18B20温度传感器
  8. python之Linux(Ubuntu)系统安装Python
  9. linux常用命令---用户相关操作
  10. 存储系列之 Linux ext2 概述