javascript
\nvar isBalanced = function(root) {\n    return getHeight(root) !== -1;\n    \n    function getHeight(root) {\n        if(!root) {\n            return 0;\n     
```\nvar isBalanced = function(root) {\n    return getHeight(root) !== -1;\n    \n    function getHeight(root) {\n        if(!root) {\n            return 0;\n        }\n        let left = getHeight(root.left);\n        let right = getHeight(root.right);\n        if(left == -1 || right == -1 || Math.abs(left - right) > 1) {\n            return -1;\n        }\n        return 1 + Math.max(left, right);\n    }\n};\n```
[]