Back to course home
0% completed
Vote For New Content
My Solution
Mohammed Dh Abbas
May 30, 2024
lass Solution: def dfs(self, node): if not node: return 0 left = self.dfs(node.left) right = self.dfs(node.right) path = 0 if right > 0 and left < 0: path = right + node.val elif left > 0 and right < 0: path = left + node.val else: path = left + right + node.val self.max_path = max(self.max_path, path) return max(left, right) + node.val def findMaximumPathSum(self, root): self.max_path = root.val self.dfs(root) return self.max_path
0
0
Comments
Comments
On this page