剑指offer(四十七)之平衡二叉树
来源:互联网 发布:手机航班查询软件 编辑:程序博客网 时间:2024/04/29 03:02
题目描述
输入一棵二叉树,判断该二叉树是否是平衡二叉树。
代码:
public class Solution { public boolean IsBalanced_Solution(TreeNode root) { if (root == null) return true; if (Math.abs(getHeight(root.left) - getHeight(root.right)) > 1) return false; return IsBalanced_Solution(root.left) && IsBalanced_Solution(root.right); } public int getHeight(TreeNode root) { if (root == null) return 0; return max(getHeight(root.left), getHeight(root.right)) + 1; } private int max(int a, int b) { return (a > b) ? a : b; }}
0 0
- 剑指offer(四十七)之平衡二叉树
- 【剑指offer】之判断二叉树平衡
- 剑指offer之平衡二叉树
- 剑指offer之平衡二叉树
- 剑指offer--平衡二叉树
- 《剑指offer》平衡二叉树
- 剑指Offer--平衡二叉树
- 剑指offer-平衡二叉树
- 剑指offer:平衡二叉树
- 剑指offer 平衡二叉树
- 剑指offer:平衡二叉树
- [剑指offer]平衡二叉树
- 剑指offer|平衡二叉树
- 《剑指offer》-平衡二叉树
- 剑指offer-平衡二叉树
- 剑指offer: 平衡二叉树
- 剑指offer:平衡二叉树
- 剑指offer-平衡二叉树
- spark 1.5、hadoop 2.7 集群环境搭建
- ffmpeg学习(3)—— ffmpeg,ffplay,ffprobe
- Error opening framebuffer device /dev/fb0
- Invert Binary Tree
- 图片缓存工具类
- 剑指offer(四十七)之平衡二叉树
- Java基础整理(二)
- Flash基础知识
- vs配置环境变量(bin文件)
- Zap[Poi2007][bzoj1101]
- 第七届ACM山东省赛-H Memory Leak
- Docker+Kubernetes linux x64 Centos7 安装
- QT编程中的-qws
- css:float之清浮动