← 返回 doordash 的题目列表Maximum Sum between Two Leaf Nodes in Binary Tree
类型:online_judge
Given a binary tree where each node contains an integer value. Find the maximum path sum between any two leaf nodes. The path must start at one leaf and end at another leaf. Implement a function to solve this problem using DFS and maintain a global maximum.
Test cases:
Input: [1, 2, 3, 4, 5, null, null], Output: 12
Input: [-10, 9, 20, null, null, 15, 7], Output: 42
Input: [2, -1, null], Output: 2
Input: [10, -9, 20, null, null, 15, 7], Output: 42
Input: [5, 4, 8, 11, null, 13, 4, 7, 2, null, null, null, null, 1], Output: 48
Example
Input
1, 2, 3, 4, 5, null, null