Pattern||✅Beats 100% DFS||BFS|| Recursion, Iteration
Intuition\nA binary tree is considered to be balanced when the difference in height of left and rightof node/root exist in the range <=1. \n\n# Approach\n1. che
# Intuition\nA binary tree is considered to be balanced when the `difference in height of left and right `of node/root exist in the range `<=1`. \n\n# Approach\n1. check the height of left\n2. check the height of right\n3. check the difference lies only in the range\n4. recursively check same for left and right nodes.\n5. done\u270C\uFE0F\n\n# Pattern\n[226. Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree/solutions/3944453/simple-pattern-beats-100-0ms-dfs-bfs-recursive-iterative/)\n[104. Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/solutions/3942675/pattern-detailed-drawing-explanation-code-java-iteration-dfs-bfs-recursion-dfs/)\n[662. Maximum Width of Binary Tree](https://leetcode.com/problems/maximum-width-of-binary-tree/solutions/3975576/beats-99t-99s-pattern-dfs-bfs/)\n[543. Diameter of Binary Tree](https://leetcode.com/problems/diameter-of-binary-tree/solutions/3976441/beats-100-time-java-recursion/)\n[110. Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree/solutions/3999211/pattern-beats-100-dfs-bfs-recursion-iteration/)\n[100. Same Tree](https://leetcode.com/problems/same-tree/solutions/3976650/pattern-understanding-beats-100-t-99-s-iterative-bfs-dfs-recursive-dfs-java/)\n[572. Subtree of Another Tree](https://leetcode.com/problems/subtree-of-another-tree/solutions/3977112/pattern-beats-97-time-and-space-recursive-dfs-iterative-bfs-and-dfs/)\n[199. Binary Tree Right Side View- NO TO BE MISSED](https://leetcode.com/problems/binary-tree-right-side-view/solutions/3987723/one-stop-best-binary-tree-pattern-solution-iterative-recursion-dfs-bsf/)\n[235. Lowest Common Ancestor of a Binary Search Tree\n](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/solutions/3977479/beats-98-time-o-logn-96-space-o-1-5ms-java-recursive-and-iterative/)\n\n<img src="https://assets.leetcode.com/users/images/c80e225b-0723-4163-9345-0e17d60e2a8e_1693798353.9626634.png" alt="closed_paren" title="Please Upvote\uD83D\uDC4D" style="display: block; margin: 0 auto;" width="550" height="250"/>\n\n**This is a tree series solution, please upvote if you find this helpful**\n\n[CHECK_THIS_OUT](https://genesis.hashnode.dev/unveiling-the-power-of-web-scraping-a-comprehensive-guide)\n\n\n# Complexity\n```\n- Time complexity:O(n)\n\n- Space complexity:O(n)\n```\n\n# Code\n```java []\nclass Solution {\n\n    public boolean isBalanced(TreeNode root) {\n        if (root == null) {\n            return true; // An empty tree is considered balanced\n        }\n        \n        int left = depth(root.left);\n        int right = depth(root.right);\n        \n        // Check the balance condition and recurse for left and right subtrees\n        return Math.abs(left - right) <= 1 && isBalanced(root.left) && isBalanced(root.right);\n    }\n    \n    // Helper function to calculate the depth of a tree\n    public int depth(TreeNode root) {\n        if (root == null) {\n            return 0;\n        }\n        return Math.max(depth(root.left), depth(root.right)) + 1;\n    }\n}\n\n```\n```java []\nclass Solution {\n    public boolean isBalanced(TreeNode root) {\n\n        if (root == null)  return true;\n    \n\t\tif (Height(root) == -1)  return false;\n\t\treturn true;\n\t}\n    \n\tpublic int Height(TreeNode root) {\n        \n\t\tif (root == null)  return 0;\n        \n\t\tint leftHeight = Height(root.left);\n\t\tint rightHight = Height(root.right);\n        if (leftHeight == -1) return -1;\n\t\tif (rightHight == -1)  return -1;\n        \n        if (Math.abs(leftHeight - rightHight) > 1)  return -1;\n    \n\t\treturn Math.max(leftHeight, rightHight) + 1;\n    }\n}\n```\n\n
['Java']