104.二叉树的最大深度
def depth(p):
if p == None:
return 1
else:
return 1 + max(depth(p.right), depth(q.left))
if root == None:
return 0
else:
return max(depth(root.right), depth(root.left))
ok!二十分钟以内一次性通过搞定!!不妄研究了两天的树!!
别人依然两行搞定
if root == None:
return 0
else:
return 1 + max(maxDepth(root.right), maxDepth(root.left))