110. Balanced Binary Tree
来源:互联网 发布:魔方数据是什么 编辑:程序博客网 时间:2024/04/28 00:18
二叉平衡树的判断,使用递归的方法
class Solution {public: bool isBalanced(TreeNode* root) { return findDepth(root) == -1 ? false : true; } int findDepth(TreeNode* root) { if(!root) return 0; int leftDepth = findDepth(root->left); if(leftDepth == -1) return -1; int rightDepth = findDepth(root->right); if(rightDepth == -1) return -1; if(abs(leftDepth-rightDepth) > 1) return -1; return max(leftDepth, rightDepth)+1; }};
0 0
- 110.Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- 110. Balanced Binary Tree
- HTTPDNS 在 iOS 中的实践
- spring mvc 配置 / 与 /* 问题
- 团灭Windows进程通信(四)——共享库就是加料的方便面
- 乒乓球
- KVO原理浅析
- 110. Balanced Binary Tree
- unity3d fpscontrol中mouselook脚本的解释
- Keil_MDK 中绝对地址定位问题
- linux mysql大小写敏感导致 spring security 无法保存登陆的token
- 关于Java的包装类
- 1>Pupil.obj : error LNK2005: "public: __thiscall Pupil::Pupil(void)" (??0Pupil@@QAE@XZ) 已经在 Main.obj
- 预处理宏和内联函数
- JVM内幕:Java虚拟机详解
- Freemarker中的指令、数据类型、命名空间、内建函数