We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 48b4fd5 + 35bcfc8 commit 55530e1Copy full SHA for 55530e1
solution/0100-0199/0110.Balanced Binary Tree/Solution.cpp
@@ -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