Skip to content

Commit 55530e1

Browse files
authored
Merge pull request doocs#320 from Stackingrule/dev
feat:add Solution.cpp for 0110.Balanced Binary Tree
2 parents 48b4fd5 + 35bcfc8 commit 55530e1

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public:
3+
bool isBalanced(TreeNode* root) {
4+
if (!root) return true;
5+
if (abs(getDepth(root->left) - getDepth(root->right)) > 1) return false;
6+
return isBalanced(root->left) && isBalanced(root->right);
7+
}
8+
9+
private:
10+
int getDepth(TreeNode *root) {
11+
if (!root) return 0;
12+
return 1 + max(getDepth(root->left), getDepth(root->right));
13+
}
14+
};

0 commit comments

Comments
 (0)