My short O(n) recursive C++ code
class Solution {\n    public:\n        int height(TreeNode *root)\n        {\n            if(root == NULL) return 0;\n            int hl = height(root->left);\n
    class Solution {\n    public:\n        int height(TreeNode *root)\n        {\n            if(root == NULL) return 0;\n            int hl = height(root->left);\n            int hr = height(root->right);\n            if (hl == -1 || hr == -1 || abs(hl - hr) > 1) return -1;\n            return max(hl, hr) + 1;\n        }\n        bool isBalanced(TreeNode *root) {\n            return height(root) != -1;\n        }\n    };
['Recursion']