C++ Simple Recursive Code
Intuition\n Describe your first thoughts on how to solve this problem. \nValues in recursion are returned from bottom to top\n\n# Approach\n Describe your appro
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nValues in recursion are returned from bottom to top\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nCalculate height of the tree and in each recursive call check wether the left and right subtree satisfy the constraint\n# Complexity\n- Time complexity: O(N) where N is number of Nodes\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(height of binary tree) due to recursion\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n\n    bool ans;\n\n    int getHt(TreeNode* root){\n        if(!root) return 0;\n        int lst = getHt(root->left);\n        int rst = getHt(root->right);\n        if(abs(lst-rst) > 1) ans = false;\n        return 1 + max(lst, rst);\n\n    }\n    bool isBalanced(TreeNode* root) {\n        ans = true;\n        getHt(root);\n        return ans;\n    }\n};\n```
['Recursion', 'Binary Tree', 'C++']