13min,python真的爽,可以返回两个值,一遍通过
class Solution:
def IsBalanced_Solution(self, pRoot):
result,_=self.is_balanced(pRoot)
return result
def is_balanced(self,pRoot):
if not pRoot:return True,0
t1,left_n=self.is_balanced(pRoot.left)
t2,right_n=self.is_balanced(pRoot.right)
if t1 and t2 and abs(left_n-right_n)<2:return True,max(left_n,right_n)+1
return False,0










网友评论