We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Learn more about funding links in repositories.
Report abuse
1 parent 2ec135c commit 854a901Copy full SHA for 854a901
110. Blanced Binary Tree
@@ -0,0 +1,27 @@
1
+ int height(TreeNode* root){
2
+ if(!root)return 0;
3
+ // int leftheight = height(root->left);
4
+ // int rightheight = height(root->right);
5
+ int ans = 1+ max(height(root->left),height(root->right));
6
+ return ans;
7
+ }
8
+ bool isBalanced(TreeNode* root) {
9
+ if(!root)return true;
10
+ //1 case
11
+ // int leftHeight = height(root->left);
12
+ // int rightHeight = height(root->right);
13
+ int diff = abs(height(root->left)-height(root->right));
14
+
15
+ //bool ans = (diff <=1);
16
17
+ //Recursion
18
+ // int leftans = isBalanced(root->left);
19
+ // int rightans = isBalanced(root->right);
20
21
+ if((diff <=1) && isBalanced(root->left) && isBalanced(root->right)){
22
+ return true;
23
24
+ else{
25
+ return false;
26
27
0 commit comments