110.Balanced Binary Tree
# Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right class Solution: def isBalanced(self, root: TreeNode) -> bool: if root == None: return True l_depth, r_depth = 0 , 0 if root.left != None: l_depth = self.subtreeHight(root.left) if root.right != None: r_depth = self.subtreeHight(root.right) if abs(l_depth - r_depth) > 1: return False else: return self.isBalanced(root.left) and self.isBalanced(root.right) def subtreeHight(self, root): if root == None: return 0 return max(self.subtreeHight(root.left), self.subtreeHight(root.right)) + 1