【发布时间】:2020-06-21 03:35:24
【问题描述】:
我想测试一棵二叉树的总深度,所以写了如下代码:
def nodeDepths(root):
return depthSum(root, 0)
def depthSum(node, depth)
if node.left:
depth += depthSum(root.left, depth+1)
if node.right:
depth += depthSum(root.right, depth+1)
return depth
# This is the class of the input binary tree.
class BinaryTree:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
然后我遇到了以下错误,请告诉我如何解决这个问题。
Traceback(最近一次调用最后一次): 文件“main.py”,第 7 行,在 导入 json_wrapper 文件“/tester/json_wrapper.py”,第 3 行,在 导入程序 文件“/tester/program.py”,第 4 行 def depthSum(节点,深度) ^ SyntaxError:无效的语法 退出状态 1
【问题讨论】: