I want to test the total depth of a binary tree, so I wrote the following code:
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
I then encountered the following error, please let me know how to fix this.
Traceback (most recent call last): File "main.py", line 7, in import json_wrapper File "/tester/json_wrapper.py", line 3, in import program File "/tester/program.py", line 4 def depthSum(node, depth) ^ SyntaxError: invalid syntax exit status 1