var isBalanced = function (root) {
let res = true
// 计算左右子树的最大深度
const maxDepth = (root) => {
if (!root) return 0
const r = maxDepth(root.right)
const l = maxDepth(root.left)
if (Math.abs(r - l) > 1) {
res = false
}
return Math.max(r, l) + 1
}
maxDepth(root)
return res
};