> For the complete documentation index, see [llms.txt](https://nataliekung.gitbook.io/solutions/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nataliekung.gitbook.io/solutions/balanced_binary_tree.md).

# Balanced Binary Tree

class Solution {

public:

bool isBalanced(TreeNode\* root) {

if(!root)

return true;

return depth(root)>0;

}

int depth(TreeNode\* root){

if(!root)

return 0;

int l=depth(root->left), r=depth(root->right);

if(l<0||r<0||abs(l-r)>1) return -1;//剪枝 every node!!!!!!!!!!!!!!!!!!!!!!!!!!!!

return 1+max(l,r);

}

};
