You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Data Structures/Trees/BinaryTree_Maximum_Path_Sum.cpp
+9Lines changed: 9 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -24,6 +24,13 @@ Explanation: The optimal path is 15 -> 20 -> 7 with a path sum of 15 + 20 + 7 =
24
24
*/
25
25
classSolution {
26
26
public:
27
+
/**The logic is very simple. The maximum path sum will always consist of a node and its left and right sub-tree maximum path sum. As the node values can be negative also so
28
+
4 cases comes here .
29
+
1) A node and its both sub-trees will constitute the sum
30
+
2) Only a node and its left sub-tree will constitute the sum
31
+
3) Only a node and its right sub-tree will constitute the sum
0 commit comments