-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaximum_path_sum.cpp
More file actions
54 lines (44 loc) · 996 Bytes
/
Copy pathmaximum_path_sum.cpp
File metadata and controls
54 lines (44 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
////////////////////////////////////////////////////////////////////////////////
//
// Maximum path sum
// from https://leetcode.com/problems/binary-tree-maximum-path-sum/description/
//
// Description
// Given a non-empty binary tree, find the maximum path sum.
//
// for this problem, a path is defined as any sequence of nodes from some
// starting node to any node in the tree along the parent-child connnections,
// The path must contain at least one node and does not need to go through the
// root.
//
// 1
// / \
// 2 3
// output: 6 (2 + 1 + 3)
//
// -10
// / \
// 9 20
// / \
// 15 7
// output: 42 (15 + 20 + 7)
//
// Solution
//
////////////////////////////////////////////////////////////////////////////////
#include <iostream>
struct TreeNode {
int val;
TreeNode *left, *right;
TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
};
int max_path_sum(TreeNode *root) {
}
int main(int argc, char** argv)
{
{
}
{
}
return 0;
}