class Solution: def isBalanced(self, root: TreeNode) -> bool: if not root: return True def helper(node): if not node: return 0 left=helper(node.left) right=helper(node.right) return max(left,right)+1 return abs(helper(root.left)-helper(root.right))<=1 and self.isBalanced(root.left) and self.isBalanced(root.right)
执行用时 :76 ms, 在所有 python3 提交中击败了60.84%的用户
内存消耗 :19.6 MB, 在所有 python3 提交中击败了5.15%的用户
——2019.11.15
原文地址:https://www.cnblogs.com/taoyuxin/p/11865355.html
时间: 2024-10-19 22:33:59