Simple Python Solution


  • 0
    C
    # Definition for a binary tree node.
    # class TreeNode(object):
    #     def __init__(self, x):
    #         self.val = x
    #         self.left = None
    #         self.right = None
    
    class Solution(object):
        def isBalanced(self, root):
            """
            :type root: TreeNode
            :rtype: bool
            """
            def isB(N, L=0):
                if not N: return L
                LL= isB(N.left, L+1)
                RL = isB(N.right, L+1)
                return max(LL,RL), abs(LL-RL) <= 1 and LB and RB
                    
            return isB(root)[1]

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.