MCPcopy Index your code
hub / github.com/BeeBombshell/Python-DSA / Solution

Class Solution

Tree Data Structure/binarytree_maxpath.py:33–44  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31 insert(Tree, element)
32 return Tree
33class Solution(object):
34 def maxPathSum(self, root):
35 self.ans = -float('inf')
36 self.solve(root)
37 return self.ans
38 def solve(self,node):
39 if not node or node.data == 0:
40 return 0
41 left = max(0,self.solve(node.left))
42 right = max(0,self.solve(node.right))
43 self.ans = max(self.ans,left+right+node.data)
44 return node.data + max(left,right)
45ob = Solution()
46root = make_tree([-10,9,10,None,None,15,7])
47print(ob.maxPathSum(root))

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected