Balanced Binary Tree LeetCode Solution

🔥 Day 82 of my LeetCode Journey 🔥 📘 Problem: 110. Balanced Binary Tree 🎯 Difficulty: Easy 🔹 Problem Statement: Given a binary tree, determine if it is height-balanced. A binary tree is balanced if the height difference between the left and right subtree of every node is not more than 1. 🔹 Approach Used: Traverse the tree using Depth First Search (DFS) Calculate the height of left and right subtrees recursively If the height difference exceeds 1, return -1 to indicate the tree is not balanced Otherwise, return the height of the current node Finally, check if the returned value is -1 or not 🔹 Key Concepts: Binary Tree traversal Depth First Search (DFS) Recursion Height calculation of tree 🔹 Learning: Instead of calculating heights separately for every node (which would increase complexity), this approach combines height calculation and balance checking in a single traversal, making the solution more efficient. Time Complexity: O(n) Space Complexity: O(h) (recursion stack) #LeetCode #Day82 #Java #BinaryTree #DFS #Recursion #DSA #ProblemSolving #CodingJourney

  • text

To view or add a comment, sign in

Explore content categories