Balanced Binary Tree LeetCode Solution

🚀Day 33 of #100DaysOfCode 📌 LeetCode 110 – Balanced Binary Tree Today I solved the Balanced Binary Tree problem, which checks whether a binary tree is height-balanced. 👉 A binary tree is considered balanced if for every node, the height difference between its left and right subtrees is at most 1. 💡 Key Learning Instead of recalculating heights repeatedly (which is inefficient), I used a bottom-up DFS approach: Return the height of a subtree if it’s balanced Return -1 immediately if an imbalance is detected This helps in early stopping and keeps the solution optimal. ⚙️ Complexity Time: O(n) Space: O(h), where h is the height of the tree 🧠 Takeaway Optimizing recursive solutions by combining checks with return values can significantly improve performance and clarity. Consistency > Motivation 💪 On to the next problem! #LeetCode #DataStructures #BinaryTree #Python #CodingJourney #ProblemSolving #100DaysOfCode #LearningEveryDay

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories