Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Balanced Binary Tree

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 depth of the two subtrees of every node never differ by more than 1.





bool isBalanced(TreeNode *root) {
	    bool unbalenced = false;
	    getHeight(unbalenced, root);
	    return !unbalenced;
int getHeight(bool &unbalenced, TreeNode *root) {
    if (root == NULL || unbalenced)
	    return -1;
    int left = getHeight(unbalenced, root->left);
    int right = getHeight(unbalenced, root->right);
    if (abs(left, right) > 1) {
	    unbalenced = true;
    return 1 + (left > right ? left : right);
You can’t perform that action at this time.