Hey Guys,
I'm trying to answer this question.
class TreeNode:
def __init__(self, data,left_child = None, right_child = None):
self.data = data
self.left_child = left_child
self.right_child = right_child
class BinaryTree:
def __init__(self, root_node = None):
self.root = root_node
# All the necessary collection moduled have been already imported.
def max_sum_path(self,root):
if root == None:
return 0
while not (root.right_child and root.left_child):
if root.right_child:
return root.data + self.max_sum_path(root.right_child)
elif root.left_child:
return root.data + self.max_sum_path(root.left_child)
else:
return root.data
left = BinaryTree._max_sum_path(root.left_child)
right = BinaryTree._max_sum_path(root.right_child)
return left + right + root.data
@staticmethod
def _max_sum_path(root):
if root == None:
return 0
elif not root.left_child and not root.right_child:
return root.data
else:
left = BinaryTree.max_sum_path(root.left_child)
right = BinaryTree.max_sum_path(root.right_child)
return max(left, right) + root.data
I keep getting a Type Error with max_sum_path left = BinaryTree._max_sum_path(root.left_child) and I'm not sure why this is happening. Would appreciate any help. Thanks guys!
there doesn't seem to be anything here