Return the maximum sum of a nonempty simple path in a binary tree. A path can begin and end anywhere and may not repeat a node.
Example 1
Argument 1 tree: level-order input; omitted children are null.root = [-5,4,8,null,null,3,9]
20
Explanation
The best path 3->8->9 totals 20; extending through -5 lowers its sum.
Example 2
Argument 1 tree: level-order input; omitted children are null.Explanation
The path must be nonempty, so choose least-negative node -3.
Example 3
Argument 1 tree: level-order input; omitted children are null.Explanation
The only path contains value 2.
Constraints
- 1 <= number of nodes <= 10000
- Values are -1000..1000
Function contractmaxPathSumArguments: tree