> For the complete documentation index, see [llms.txt](https://code-snippets.hbamithkumara.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://code-snippets.hbamithkumara.com/leetcode/problems/101-200/balanced-binary-tree.md).

# 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.

### Constraints

### Approach

### Links

* [GeeksforGeeks](https://www.geeksforgeeks.org/how-to-determine-if-a-binary-tree-is-balanced/)
* [Leetcode](https://leetcode.com/problems/balanced-binary-tree/)
* [ProgramCreek](https://www.programcreek.com/2013/02/leetcode-balanced-binary-tree-java/)
* YouTube

### **Examples**

{% tabs %}
{% tab title="Example 1" %}
**Input:** \[3, 9, 20, null, null, 15, 7]

<div align="left"><img src="/files/-MFzAvu1OFrOqG9lFTpZ" alt=""></div>

**Output:** true
{% endtab %}

{% tab title="Example 2" %}
**Input:** \[1, 2, 2, 3, 3, null, null, 4, 4]

<div align="left"><img src="/files/-MFzBI2VYAnEu-W-nrfk" alt=""></div>

**Output:** false
{% endtab %}
{% endtabs %}

### **Solutions**

{% tabs %}
{% tab title="TreeNode" %}

```java
// Definition for a binary tree node.
public class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    
    TreeNode() {}
    
    TreeNode(int val) { this.val = val; }
    
    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}
```

{% endtab %}

{% tab title="Solution 1" %}

```java
/**
 * Time complexity : 
 * Space complexity : 
 */

class Solution {
    public boolean isBalanced(TreeNode root) {
        if(root == null) return true;
        
        if(Math.abs(height(root.left)-height(root.right)) > 1) {
            return false;
        }
        
        return isBalanced(root.left) && isBalanced(root.right);
    }
    
    private int height(TreeNode root) {
        if(root == null) return 0;
        
        return 1 + Math.max(height(root.left), height(root.right));
    }
}
```

{% endtab %}

{% tab title="Solution 2" %}

```java
/**
 * Time complexity : 
 * Space complexity : 
 */

class Solution {
    private int diff = 0;
    
    public boolean isBalanced(TreeNode root) {
        if(root == null) return true;
        
        height(root);
        
        return diff <= 1;
    }
    
    private int height(TreeNode root) {
        if(root == null) return 0;
        
        int lh = height(root.left);
        int rh = height(root.right);
        
        diff = Math.max(diff, Math.abs(lh-rh));
        
        return 1 + Math.max(lh, rh);
    }
}
```

{% endtab %}
{% endtabs %}

### **Follow up**

*
