global是全局变量为什么改变不了tell的值为1
# global tell
class Solution:
def isBalanced(self, root: TreeNode) -> bool:
tell=0
def f1(root:TreeNode):
nonlocal tell
if root is None:
return 0
left=f1(root.left)
right=f1(root.right)
# print(type(right))
if abs(left -right)>1:
tell=1
return 2
else :
return max(left,right)+1
f1(root)
if tell:
return False
else:
return True