File tree Expand file tree Collapse file tree
data_structures/binary_tree Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- """
2- A path in a binary tree is a sequence of nodes where each pair
3- of adjacent nodes in the sequence has an edge connecting
4- them. A node can only appear in the sequence at most once. Note
5- that the path does not need to pass through the root.
6-
7- The path sum of a path is the sum of the node's values in the path.
8-
9- Given the root of a binary tree, return the maximum path sum of any non-empty path.
10-
11- Leetcode Reference : https://leetcode.com/problems/binary-tree-maximum-path-sum/
12- """
131from __future__ import annotations
2+
143from dataclasses import dataclass
154
165
6+ # Leetcode Reference : https://leetcode.com/problems/binary-tree-maximum-path-sum/
177@dataclass
188class TreeNode :
199 val : int
@@ -57,7 +47,7 @@ class GetMaxPathSum:
5747 29
5848 """
5949
60- def __init__ (self , root ) -> None :
50+ def __init__ (self , root : TreeNode ) -> None :
6151 self .sum = - 9999999999
6252 self .root = root
6353
@@ -126,4 +116,3 @@ def construct_tree() -> TreeNode:
126116 print ("Given example output: " , max_sum )
127117
128118 doctest .testmod ()
129-
You can’t perform that action at this time.
0 commit comments