LeetCode110. Balanced Binary Tree
2016-12-30 11:08
447 查看
题目链接
判断是否为平衡二叉树。
判断是否为平衡二叉树。
class Solution { public: bool isBalanced(TreeNode* root) { if(root == NULL) return 1; int l1 = getDepth(root->left); int l2 = getDepth(root->right); if(abs(l1-l2)>1) return 0; return isBalanced(root->left)&&isBalanced(root->right); } int getDepth(TreeNode* root){ if(root == NULL) return 0; return max(getDepth(root->left), getDepth(root->right))+1; } };
相关文章推荐
- [LeetCode]110. Balanced Binary Tree
- LeetCode 110. Balanced Binary Tree
- [勇者闯LeetCode] 110. Balanced Binary Tree
- LeetCode笔记:110. Balanced Binary Tree
- Leetcode 110. Balanced Binary Tree
- LeetCode 110. Balanced Binary Tree 递归求解
- Leetcode#110. Balanced Binary Tree(判断是否是平衡二叉树)
- 剑指offer 面试题39:判断平衡二叉树(LeetCode 110. Balanced Binary Tree) 题解
- LeetCode *** 110. Balanced Binary Tree
- LeetCode 110. Balanced Binary Tree
- [LeetCode] 110. Balanced Binary Tree 解题思路
- [LeetCode]--110. Balanced Binary Tree
- [LeetCode] 110. Balanced Binary Tree
- Leetcode 110. Balanced Binary Tree
- LeetCode 110. Balanced Binary Tree
- [leetcode]110. Balanced Binary Tree
- 【leetcode】110. Balanced Binary Tree
- [leetcode] 110. Balanced Binary Tree 解题报告
- Leetcode:110. Balanced Binary Tree(JAVA)
- [LeetCode] 110. Balanced Binary Tree