剑指offer---平衡二叉树
来源:互联网 发布:lol国服mac版本几时出 编辑:程序博客网 时间:2024/06/05 03:26
输入一棵二叉树,判断该二叉树是否是平衡二叉树
import java.lang.Math;class ResultType { boolean isBST; int deepth; public ResultType(boolean isBST, int deepth) { this.isBST = isBST; this.deepth = deepth; }}public class Solution { public boolean IsBalanced_Solution(TreeNode root) { if (root == null) { return true; } ResultType result = util(root); return result.isBST; } private ResultType util(TreeNode root) { if (root == null) { return new ResultType(true, 0); } ResultType left = util(root.left); ResultType right = util(root.right); if (left.isBST && right.isBST && Math.abs(left.deepth - right.deepth) <= 1) { return new ResultType(true, Math.max(left.deepth, right.deepth) + 1); } return new ResultType(false, -1); }}
阅读全文
0 0
- 剑指offer--平衡二叉树
- 《剑指offer》平衡二叉树
- 剑指Offer--平衡二叉树
- 剑指offer-平衡二叉树
- 剑指offer:平衡二叉树
- 剑指offer 平衡二叉树
- 剑指offer:平衡二叉树
- [剑指offer]平衡二叉树
- 剑指offer|平衡二叉树
- 《剑指offer》-平衡二叉树
- 剑指offer-平衡二叉树
- 剑指offer: 平衡二叉树
- 剑指offer:平衡二叉树
- 剑指offer-平衡二叉树
- 剑指offer 平衡二叉树
- 【剑指offer】平衡二叉树
- 剑指offer-平衡二叉树
- 剑指offer--平衡二叉树
- 基于Unity3D的异步加载场景的实现
- 数据结构与算法分析(Java语言描述)(10)—— (三向切分)快速排序
- SPI的简单介绍
- 初试struts2
- python之数据驱动DDT安装
- 剑指offer---平衡二叉树
- CSS——水平(横向滚动条)
- 【深入理解计算机系统】系统级I/O
- 欢迎使用CSDN-markdown编辑器
- SPI的使用场景
- 运用字符串中位置的调换,比较一个旋转与另一个字符串是否相同。上篇博客的拓展。
- 1、安装与卸载
- Unity打包发布设置Bundle Identifier
- ionic3开发系列——ionic3懒加载配置