leetcode_c++:树:Balanced Binary Tree(110)
来源:互联网 发布:淘宝要怎么成旗舰店 编辑:程序博客网 时间:2024/06/08 16:47
Given a binary tree, determine if it is height-balanced.
For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.
class Solution {private: bool balanceFlag; int getTreeDepth(TreeNode *root) { if (!root || !balanceFlag) return 0; int sz1 = getTreeDepth(root->left); int sz2 = getTreeDepth(root->right); if (abs(sz1 - sz2) > 1) balanceFlag = false; return max(sz1, sz2) + 1; }public: bool isBalanced(TreeNode *root) { balanceFlag = true; getTreeDepth(root); return balanceFlag; }};
0 0
- leetcode_c++:树:Balanced Binary Tree(110)
- leetcode_c++:树:Binary Tree Paths(257)
- 110Balanced Binary Tree
- #110 Balanced Binary Tree
- 110Balanced Binary Tree
- 110 Balanced Binary Tree
- 110Balanced Binary Tree
- 110 - Balanced Binary Tree
- 树 Balanced Binary Tree
- leetcode_c++:树: Minimum Depth of Binary Tree(111)
- leetcode_c++:树: Flatten Binary Tree to Linked List(114)
- leetcode_c++:树:Serialize and Deserialize Binary Tree(297)
- LeetCode 110 Balanced Binary Tree(平衡二叉树)(*)
- 110:Balanced Binary Tree【树】【DFS】
- LeetCode(110) Balanced Binary Tree
- Balanced Binary Tree(平衡二叉树)
- leetcode_c++:树:Validate Binary Search Tree(098)
- leetcode_c++:树:Recover Binary Search Tree(099)
- Vijos P1464 积木游戏(动态规划)
- codeblock 结合 ofxFaceTracker 人脸识别
- Servlet含义与工作原理
- EPPlus 读写 Excel 资料收集
- 地杰斯特拉算法
- leetcode_c++:树:Balanced Binary Tree(110)
- MySQL基础五之子查询和连接
- Android 选择商品属性sku
- tomcat和weblogic下使用druid 驱动jndi
- 搭建使用numpy, scipy, scikit-learn的环境
- 最全的常用正则表达式大全——包括校验数字、字符、一些特殊的需求等等
- bootstrap suggest 前端输入框下拉提示、搜索建议插件
- 增加属性功能
- Android 之 Handler 使用