Balanced Binary Tree
来源:互联网 发布:上海美工刀片批发2011 编辑:程序博客网 时间:2024/05/22 12:51
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { public boolean isBalanced(TreeNode root) { return maxDepth(root) != -1; } private int maxDepth (TreeNode node) { if (node == null) { return 0; } int left = maxDepth(node.left); int right = maxDepth(node.right); if (left == -1 || right == -1 || Math.abs(left - right) > 1) { return -1; } return Math.max(left, right) + 1; }}
0 0
- Balanced binary tree 扩展
- LeetCode: Balanced Binary Tree
- [LeetCode]Balanced Binary Tree
- LeetCode Balanced Binary Tree
- [Leetcode] Balanced Binary Tree
- LeetCode : Balanced Binary Tree
- LeetCode Balanced Binary Tree
- [LeetCode] Balanced Binary Tree
- Balanced Binary Tree
- Balanced Binary Tree
- 【leetcode】Balanced Binary Tree
- Balanced Binary Tree
- [LeetCode]Balanced Binary Tree
- Balanced Binary Tree
- Balanced Binary Tree
- [LeetCode] Balanced Binary Tree
- [Leetcode]Balanced Binary Tree
- [leetcode]Balanced Binary Tree
- C语言数据类型
- maven下载源代码,解决中文注释为乱码的问题
- 凸优化和非凸优化
- 相似与相关
- easyui datagrid的table标签使用注意
- Balanced Binary Tree
- Android NDK开发篇(一):新版NDK环境搭建(免Cygwin,超级快)
- MYSQL下什么命令查看当前正在使用的数据库
- 动态列表
- POJ 3122-Pie(二分+精度)
- Letex画复杂表格的方法
- 详解:apache启用gzip压缩方法(二)
- android平台蓝牙编程
- Yii2-多表关联查询(with、join、joinwith)示例