We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7ef5ab0 commit d1457dfCopy full SHA for d1457df
17 - Binary Tree Data Structure Problems/08 - Balanced Tree Check/main.cpp
@@ -0,0 +1,21 @@
1
+class Solution{
2
+ public:
3
+ int heights(Node* root){
4
+ if(root == NULL) return 0;
5
+
6
+ int left = heights(root -> left);
7
+ if(left == -1) return -1;
8
9
+ int right = heights(root -> right);
10
11
12
+ if(abs(left - right) > 1) return -1;
13
14
+ return max(left, right) + 1;
15
+ }
16
+ bool isBalanced(Node *root)
17
+ {
18
+ return heights(root) != -1;
19
20
21
+};
0 commit comments