标签:__init__ subject scribe title init max turn 输入 深度
1 # -*- coding:utf-8 -*- 2 # class TreeNode: 3 # def __init__(self, x): 4 # self.val = x 5 # self.left = None 6 # self.right = None 7 class Solution: 8 def IsBalanced_Solution(self, pRoot): 9 # write code here 10 if not pRoot: 11 return True 12 if abs(self.tree(pRoot.left) -self.tree(pRoot.right))>1: 13 return False 14 return self.IsBalanced_Solution(pRoot.left) and self.IsBalanced_Solution(pRoot.right) 15 16 def tree(self,pRoot): 17 # 求深度 18 if not pRoot: 19 return 0 20 if not pRoot.left and not pRoot.right: 21 return 1 22 return max(self.tree(pRoot.left),self.tree(pRoot.right))+1 23 24
标签:__init__ subject scribe title init max turn 输入 深度
原文地址:https://www.cnblogs.com/shuangcao/p/12793177.html