Balanced Binary Tree (Leetcode 110)

Technique: FAITH technique of Recursion

Problem Link: https://leetcode.com/problems/balanced-binary-tree/

class Solution:
    
    def isBalanced(self, root: Optional[TreeNode]) -> bool:
             
        def fun(root):
            if(root is None):
                return [True,0]
            l=fun(root.left)
            r=fun(root.right)

            if(l[0] and r[0] and abs(l[1]-r[1])<2):
                return [True,max(l[1],r[1])+1]
            return [False,0]
    
        ans=fun(root)
        return ans[0]

Last updated