# LeetCode: Balanced Binary Tree Solution

Modified version of "Maximum Depth of Binary Tree"

## Approach

During the calculation of tree height, check the different in height between two subtrees

## Implementation

```.css-ds3kc{display:table-row;}.css-1t8atru{display:table-cell;opacity:0.5;padding-right:var(--chakra-space-6);-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;text-align:right;}1.css-2qghsv{display:table-cell;}var isBalanced = function (root) {2  let res = true3
4  const recursion = node => {5    if (!node) return 06
7    const leftHeight = recursion(node.left)8    const rightHeight = recursion(node.right)9
10    res &&= Math.abs(leftHeight - rightHeight) <= 111
12    return Math.max(leftHeight, rightHeight) + 113  }14
15  recursion(root)16
17  return res18}```

Original problem

## Similar problems

Maximum Depth of Binary Tree

leetcode

recursion

tree

binary tree

dfs

## Next Post

LeetCode: Maximum Depth of Binary Tree

Sep 3, 2022

Explanation is hard

## Previous Post

LeetCode: Invert Binary Tree

Sep 2, 2022

A Broken Interview: The Origin

Search Posts