###### tags: `leetcode`
# Question 110. Balanced Binary Tree
### Description:
Given a binary tree, determine if it is height-balanced.
For this problem, a height-balanced binary tree is defined as:
a binary tree in which the left and right subtrees of every node differ in height by no more than 1.
### Solution:
- DFS:
- find the depth of left and right subtree.
### AC code
```cpp=
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
*/
class Solution {
public:
int depth(TreeNode* root){
if(root==NULL)
return 0;
return max(depth(root->left), depth(root->right))+1;
}
bool isBalanced(TreeNode* root) {
if(root==NULL)
return true;
int dl = depth(root->left);
int dr = depth(root->right);
if(abs(dl-dr)>1)
return false;
return isBalanced(root->left)&&isBalanced(root->right);
}
};
```